using Ewide.Application.Entity; using Ewide.Application.Service.HouseProjectInfo.Dto; using Ewide.Core; using Ewide.Core.Service; using Furion.DatabaseAccessor; using Furion.DatabaseAccessor.Extensions; using Furion.DependencyInjection; using Furion.DynamicApiController; using Mapster; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Ewide.Application.Service.HouseProjectInfo { /// /// 项目管理相关服务 /// [ApiDescriptionSettings(Name = "HouseProjectInfo", Order = 170)] public class HouseProjectInfoService : IHouseProjectInfoService, ITransient, IDynamicApiController { private readonly IRepository _houseProjectInfoRep; public HouseProjectInfoService(IRepository houseProjectInfoRep) { _houseProjectInfoRep = houseProjectInfoRep; } /// /// 添加项目 /// /// /// [HttpPost("/houseProjectInfo/add")] public async Task AddProject(AddProjectInput input) { await _houseProjectInfoRep.InsertNowAsync(input.Adapt()); } /// /// 删除项目 /// /// /// [HttpPost("/houseProjectInfo/delete")] public async Task DeleteProject(DeleteProjectInput input) { var project = _houseProjectInfoRep.FirstOrDefault(p => p.Id == input.ID) ; await project.DeleteNowAsync(); } /// /// 编辑项目 /// /// /// [HttpPost("/houseProjectInfo/edit")] public async Task UpdateProject(AddProjectInput input) { var project = input.Adapt(); await project.UpdateNowAsync(); } /// /// 通过ID获取项目 /// /// /// [HttpGet("/houseProjectInfo/detailById")] public async Task GetProjectById([Required] string id) { return await _houseProjectInfoRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == id); } /// /// 分页查询 /// /// /// [HttpGet("/houseProjectInfo/page")] public async Task QueryProjectPageList([FromQuery] HouseProjectInfoInput input) { var areaID = !string.IsNullOrEmpty(input.AreaID); var projects = await _houseProjectInfoRep.DetachedEntities .Where(areaID, p => p.AreaId == input.AreaID) .Select(p => p.Adapt()).ToPagedListAsync(input.PageNo, input.PageSize); return XnPageResult.PageResult(projects); } /// /// /// /// /// [HttpGet("/houseProjectInfo/detail")] public async Task GetProject([FromQuery] QueryProjectInput input) { var user = await _houseProjectInfoRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == input.ID); var userDto = user.Adapt(); return userDto; } } }