| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 | using AutoMapper;using OASystem.Domain;using OASystem.Domain.Dtos.Groups;using OASystem.Domain.Entities.Groups;using OASystem.Domain.Entities.Resource;using OASystem.Domain.ViewModels.Groups;using OASystem.Infrastructure.Repositories.System;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace OASystem.Infrastructure.Repositories.Groups{    public class DelegationEnDataRepository : BaseRepository<Grp_DelegationEnData, Grp_DelegationEnData>    {        private readonly IMapper _mapper;        public DelegationEnDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)        {            _mapper = mapper;        }        /// <summary>        /// 团组英文资料操作(Status:1.新增,2.修改)        /// </summary>        /// <param name="dto"></param>        /// <returns></returns>        /// <exception cref="NotImplementedException"></exception>        public async Task<Result> OpDelegationEnData(OpDelegationEnDataDto dto)        {            Result result = new Result() { Code = -2, Msg = "未知错误" };            try            {                if (dto.Status == 1)//添加                {                    string selectSql = string.Format(@"select * from Grp_DelegationEnData where Area='{0}' and Job='{1}' and IsDel='{2}'", dto.Area, dto.Job, 0);                    var grp_DelegationEnData = await _sqlSugar.SqlQueryable<Grp_DelegationEnData>(selectSql).FirstAsync();//查询是否存在                    if (grp_DelegationEnData != null)                    {                        return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };                    }                    else//不存在,可添加                    {                        Grp_DelegationEnData _DelegationEnData = _mapper.Map<Grp_DelegationEnData>(dto);                        int id = await _sqlSugar.Insertable(_DelegationEnData).ExecuteReturnIdentityAsync();                        if (id == 0)                        {                            return result = new Result() { Code = -1, Msg = "添加失败!" };                        }                        return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };                    }                }                else if (dto.Status == 2)//修改                {                    bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationEnData                    {                        Area = dto.Area,                        Job = dto.Job,                        JobEn = dto.JobEn,                        DelegationSetting = dto.DelegationSetting,                        DelegationSettingEn = dto.DelegationSettingEn,                        CreateUserId = dto.CreateUserId,                        Remark = dto.Remark,                    });                    if (!res)                    {                        return result = new Result() { Code = -1, Msg = "修改失败!" };                    }                    return result = new Result() { Code = 0, Msg = "修改成功!", Data = new { Id = dto.Id } };                }                else                {                    return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };                }            }            catch (Exception ex)            {                return result = new Result() { Code = -2, Msg = "程序错误!" };            }        }    }}
 |