1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using AutoMapper;
- using OASystem.Domain;
- using OASystem.Domain.Dtos.Resource;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.Entities.Resource;
- using OASystem.Domain.ViewModels.Resource;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OASystem.Infrastructure.Repositories.Resource
- {
- public class LocalGuideDataRepository : BaseRepository<Res_LocalGuideData, LocalGuideDataView>
- {
- private readonly IMapper _mapper;
- public LocalGuideDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
- {
- _mapper=mapper;
- }
- public async Task<Result> LocalGuideOperation(LocalGuideOperationDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- try
- {
- if (dto.Status == 1)//添加
- {
- string selectSql = string.Format(@"select * from Res_LocalGuideData where UnitArea='{0}' and UnitName='{1}' and Contact='{2}' and ContactTel='{3}'"
- , dto.UnitArea, dto.UnitName, dto.Contact, dto.ContactTel);
- var LocalGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(selectSql).FirstAsync();//查询是否存在
- if (LocalGuideData != null)
- {
- return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
-
- }
- else//不存在,可添加
- {
- Res_LocalGuideData _LocalGuideDat = _mapper.Map<Res_LocalGuideData>(dto);
- int id = await AddAsyncReturnId(_LocalGuideDat);
- if (id == 0)
- {
- return result = new Result() { Code = -1, Msg = "添加失败!" };
- }
- 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 Res_LocalGuideData
- {
- UnitArea = dto.UnitArea,
- UnitName = dto.UnitName,
- Address = dto.Address,
- Contact = dto.Contact,
- ContactTel = dto.ContactTel,
- ContactEmail = dto.ContactEmail,
- ContactFax = dto.ContactFax,
- OtherInfo = dto.OtherInfo,
- Score = dto.Score,
- SuitScore = dto.SuitScore,
- ServeScore = dto.ServeScore,
- TalkProScore = dto.TalkProScore,
- TimeScore = dto.TimeScore,
- FitScore = dto.FitScore,
- StrainScore = dto.StrainScore,
- LocalAndChineseScore = dto.LocalAndChineseScore,
- Remark = dto.Remark,
- });
- if (!res)
- {
- return result = new Result() { Code = -1, Msg = "修改失败!" };
- }
- result = new Result() { Code = 0, Msg = "修改成功!" };
- }
- }
- catch (Exception ex)
- {
- return result = new Result() { Code = -2, Msg = "程序错误!" };
- }
- return result;
- }
- }
- }
|