| | |
| | | using System; |
| | | using AutoMapper; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_BasicRepository; |
| | | using WIDESEA_Common.MaterielEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.Basic; |
| | |
| | | { |
| | | public class CustomerInfoService : ServiceBase<Dt_CustomerInfo, ICustomerInfoRepository>, ICustomerInfoService |
| | | { |
| | | public CustomerInfoService(ICustomerInfoRepository BaseDal) : base(BaseDal) |
| | | { |
| | | } |
| | | |
| | | public ICustomerInfoRepository Repository => BaseDal; |
| | | |
| | | public WebResponseContent ReceiveCustomer(CustomerInfoDTO model) |
| | | private readonly IMapper _mapper; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | public CustomerInfoService(ICustomerInfoRepository BaseDal,IMapper mapper,IUnitOfWorkManage unitOfWorkManage) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | } |
| | | /// <summary> |
| | | /// æ¥æ¶äºæå®¢æ·ä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="eRPCustomerDTO"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent ReceiveCustomer(ERPCustomerDTO eRPCustomerDTO) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | //if (model.OperateType == "0") |
| | | //{ |
| | | Dt_CustomerInfo customer = new Dt_CustomerInfo() |
| | | if (eRPCustomerDTO == null) |
| | | { |
| | | Code = model.Code, |
| | | Name = model.ShortName, |
| | | NickName = model.Name, |
| | | State = model.State.ObjToInt(), |
| | | }; |
| | | BaseDal.AddData(customer); |
| | | //} |
| | | //else if (model.OperateType == "1") |
| | | //{ |
| | | // Dt_Customer customer = BaseDal.QueryFirst(x => x.Code == model.Code); |
| | | // if (customer == null) |
| | | // { |
| | | // return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥å®¢æ·ä¿¡æ¯"); |
| | | // } |
| | | // customer.State = model.State; |
| | | // customer.Name = model.ShortName; |
| | | // customer.NickName = model.Name; |
| | | // BaseDal.UpdateData(customer); |
| | | //} |
| | | //else if (model.OperateType == "2") |
| | | //{ |
| | | // Dt_Customer customer = BaseDal.QueryFirst(x => x.Code == model.Code); |
| | | // if (customer == null) |
| | | // { |
| | | // return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥å®¢æ·ä¿¡æ¯"); |
| | | // } |
| | | // BaseDal.DeleteData(customer); |
| | | //} |
| | | return WebResponseContent.Instance.OK(); |
| | | return content.Error("客æ·ä¿¡æ¯ä¸è½ä¼ å
¥ä¸ºç©º"); |
| | | } |
| | | List<Dt_CustomerInfo> OldcustomerInfos = BaseDal.QueryData(); |
| | | |
| | | if (eRPCustomerDTO.OperateType == 1) |
| | | { |
| | | //夿é夿å
¥ |
| | | Dt_CustomerInfo? customerInfoOld = OldcustomerInfos.FirstOrDefault(x => x.CustomerCode == eRPCustomerDTO.CustomerCode); |
| | | if (customerInfoOld != null) |
| | | { |
| | | return content.Error($"客æ·{customerInfoOld.CustomerCode}å·²åå¨"); |
| | | } |
| | | Dt_CustomerInfo customerInfo = _mapper.Map<Dt_CustomerInfo>(eRPCustomerDTO); |
| | | //æ°å¢ |
| | | BaseDal.AddData(customerInfo); |
| | | } |
| | | else if (eRPCustomerDTO.OperateType == 2) |
| | | { |
| | | //夿æ¯å¦åå¨ |
| | | Dt_CustomerInfo? customerInfoOld = OldcustomerInfos.FirstOrDefault(x => x.CustomerCode == eRPCustomerDTO.CustomerCode); |
| | | if (customerInfoOld == null) |
| | | { |
| | | return content.Error($"æ´æ°å®¢æ·{eRPCustomerDTO.CustomerCode}ä¸åå¨"); |
| | | } |
| | | Dt_CustomerInfo customerInfo = _mapper.Map<Dt_CustomerInfo>(eRPCustomerDTO); |
| | | customerInfo.Id = customerInfoOld.Id; |
| | | //æ´æ° |
| | | BaseDal.UpdateData(customerInfoOld); |
| | | } |
| | | else if (eRPCustomerDTO.OperateType == 3) |
| | | { |
| | | // 夿æ¯å¦åå¨ |
| | | Dt_CustomerInfo? customerInfoOld = OldcustomerInfos.FirstOrDefault(x => x.CustomerCode == eRPCustomerDTO.CustomerCode); |
| | | if (customerInfoOld == null) |
| | | { |
| | | return content.Error($"æ´æ°å®¢æ·{eRPCustomerDTO.CustomerCode}ä¸åå¨"); |
| | | } |
| | | BaseDal.DeleteData(customerInfoOld); |
| | | } |
| | | else |
| | | { |
| | | return content.Error("æªæ¾å°æä½ç±»å"); |
| | | } |
| | | //æ´æ°æ°æ® |
| | | return content.OK("æ¥æ¶æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | content.Error(ex.Message); |
| | | } |
| | | } |
| | | public override WebResponseContent UpdateData(SaveModel saveModel) |
| | | { |
| | | saveModel.MainData.Add("state",1); |
| | | return base.UpdateData(saveModel); |
| | | return content; |
| | | } |
| | | } |
| | | } |