using AutoMapper; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Txgy.RBS.DbModel.Models; using Txgy.RBS.Framework.Api; using Txgy.RBS.IServices; namespace Txgy.RBS.Services { public class ProjectInfoService : BaseService, IProjectInfoService { private readonly IMapper _iMapper; public ProjectInfoService(ISqlSugarClient client, IMapper iMapper) : base(client) { this._iMapper = iMapper; } public ApiResult AddProjectInfo(ProjectInfoDTO project) { int res = 0; project_info project_Info = _iMapper.Map(project); res = _Client.Insertable(project_Info).ExecuteCommand(); if (res > 0) { return new ApiResult(); } return new ApiResult() { Message = "添加失败" }; } public ApiResult DeleteProjectInfo(int id) { int res= _Client.Deleteable(p=>p.id==id).ExecuteCommand(); if (res > 0) { return new ApiResult(); } return new ApiResult() { Message = "删除失败" }; } public List GetAllProjectInfo() { var projects = _Client.Queryable().ToList(); return _iMapper.Map>(projects); } public ProjectInfoDTO GetCurrentProjectInfo() { var curProject = _Client.Queryable().First(); project_info projectInfo = _Client.Queryable().First(c => c.id == curProject.current_project_id); ProjectInfoDTO projectInfoDTO= _iMapper.Map(projectInfo); return projectInfoDTO; } public ProjectInfoDTO GetProjectInfo(int id) { project_info projectInfo = _Client.Queryable().First(c => c.id == id); ProjectInfoDTO projectInfoDTO = _iMapper.Map(projectInfo); return projectInfoDTO; } public ApiResult UpdateProjectInfo(ProjectInfoDTO project) { project_info projectInfo = _iMapper.Map (project); int res= _Client.Updateable(projectInfo).ExecuteCommand(); if(res > 0) { return new ApiResult(); } return new ApiResult() { Message = "更新失败" }; } } }