Browse Source

提交分页和数据操作

master
赵新宇 2 weeks ago
parent
commit
5ac3e67660
  1. 7
      API/TaskManager.EntityFramework/IRepository/IRepository.cs
  2. 9
      API/TaskManager.EntityFramework/Repository/Repository.cs
  3. 4
      API/TaskManager.EntityFramework/Repository/Uow/Uow.cs
  4. 4
      API/Wood.Admin.WebApi/Properties/launchSettings.json
  5. 7
      API/Wood.Admin.WebApi/Startup.cs
  6. 16
      API/Wood.Service/Controllers/RecurringJobOutPageController.cs

7
API/TaskManager.EntityFramework/IRepository/IRepository.cs

@ -1,4 +1,5 @@
using System;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
@ -11,11 +12,11 @@ namespace TaskManager.EntityFramework
{
public interface IRepository<TEntity> where TEntity : BaseEntity
{
Task<TEntity> GetByIdAsync(int id);
Task<TEntity> GetByIdAsync(long id);
Task<IEnumerable<TEntity>> GetAllAsync();
Task<TEntity> AddAsync(TEntity entity);
Task UpdateAsync(TEntity entity);
Task DeleteAsync(int id);
Task DeleteAsync(long id);
Task<PagedResult<TEntity>> GetPagedAsync(PagingParams pagingParams);

9
API/TaskManager.EntityFramework/Repository/Repository.cs

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
@ -19,16 +20,16 @@ namespace TaskManager.EntityFramework.Repository
public class Repository<TEntity> : IRepository<TEntity>
where TEntity : BaseEntity
{
private readonly DbContext _context;
private readonly JobDbContext _context;
private readonly DbSet<TEntity> _dbSet;
public Repository(DbContext context)
public Repository(JobDbContext context)
{
_context = context;
_dbSet = context.Set<TEntity>();
}
public async Task<TEntity> GetByIdAsync(int id)
public async Task<TEntity> GetByIdAsync(long id)
{
return await _dbSet.FindAsync(id);
}
@ -53,7 +54,7 @@ namespace TaskManager.EntityFramework.Repository
await _context.SaveChangesAsync();
}
public async Task DeleteAsync(int id)
public async Task DeleteAsync(long id)
{
var entity = await _dbSet.FindAsync(id);
if (entity != null)

4
API/TaskManager.EntityFramework/Repository/Uow/Uow.cs

@ -17,10 +17,10 @@ namespace TaskManager.EntityFramework.Repository
public class TaskUnitOfWork : ITaskUnitOfWork
{
private readonly DbContext _context;
private readonly JobDbContext _context;
private readonly Dictionary<Type, object> _repositories = new();
public TaskUnitOfWork(DbContext context)
public TaskUnitOfWork(JobDbContext context)
{
_context = context;
}

4
API/Wood.Admin.WebApi/Properties/launchSettings.json

@ -3,7 +3,7 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8888",
"applicationUrl": "http://localhost:7629",
"sslPort": 0
}
},
@ -16,7 +16,7 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:8888"
"applicationUrl": "http://localhost:7629"
}
}
}

7
API/Wood.Admin.WebApi/Startup.cs

@ -74,10 +74,9 @@ namespace Wood.Admin.WebApi
services.AddHttpClient();
services.AddTransient<LogController>();
services.AddTransient<SupplierProPlaningService>();
services.AddTransient<TaskConifgureController>();
services.AddScoped<LogController>();
services.AddScoped<SupplierProPlaningService>();
services.AddScoped<TaskConifgureController>();
// 配置 DbContext 使用 SQL Server 连接字符串
services.AddDbContext<JobDbContext>(options =>

16
API/Wood.Service/Controllers/RecurringJobOutPageController.cs

@ -8,11 +8,13 @@ using TaskManager.Contracts.Dtos;
using TaskManager.Controllers;
using TaskManager.Entity;
using TaskManager.EntityFramework;
using TaskManager.EntityFramework;
using TaskManager.EntityFramework.Repository;
namespace TaskManager.Controllers
{
//[ApiController]
//[Route("api/[controller]")]
public class RecurringJobOutPageController<T, ToutputDetial> : RecurringJobBaseController where T : CherryReadBaseEntity, new() where ToutputDetial : CherryReadBaseEntityDto
{
@ -232,9 +234,17 @@ namespace TaskManager.Controllers
}
[HttpPut("{id}")]
public async Task<IActionResult> Update(int id, T entity)
public async Task<IActionResult> Update(T entity)
{
if (id != entity.UId) return BadRequest();
var _first=await _repository.GetByIdAsync(entity.UId);
if (_first == null)
{
return BadRequest();
}
await _repository.UpdateAsync(entity);
return NoContent();

Loading…
Cancel
Save