private void Add(CustomerEditDto dto) { ValidateEditDto(dto); if (DataDbContext.Set <Customer>().Any(c => c.MobilePhoneNumber != null && c.MobilePhoneNumber == dto.MobilePhoneNumber && c.RealName == dto.RealName)) { throw new Exception($"错误,用户名:{dto.RealName},手机号:{dto.MobilePhoneNumber}的用户已经存在,请检查后重试!"); } var customer = dto.MapTo <Customer>(); if (dto.CustomerCategoryId > 0) { var category = DataDbContext.Set <CustomerCategory>().FirstOrDefault(cc => cc.Id == dto.CustomerCategoryId); if (category == null) { throw new Exception($"错误,Id={dto.CustomerCategoryId} 的客户分类不存在!"); } customer.CustomerCategory = category; } customer.CreatorTime = DateTime.Now; customer.LastModifyTime = DateTime.Now; DataDbContext.Set <Customer>().Add(customer); DataDbContext.SaveChanges(); }
/// <summary> /// 编辑客户信息 /// </summary> protected virtual async Task UpdateCustomerAsync(CustomerEditDto input) { var entity = await _customerRepository.GetAsync(input.Id.Value); input.MapTo(entity); await _customerRepository.UpdateAsync(entity); }
/// <summary> /// 新增客户信息 /// </summary> protected virtual async Task <CustomerEditDto> CreateCustomerAsync(CustomerEditDto input) { var entity = input.MapTo <Customer>(); entity = await _customerRepository.InsertAsync(entity); return(entity.MapTo <CustomerEditDto>()); }
protected async Task CreateCustomerAsync(CustomerEditDto input) { var flag = await _customerManager.CheckCodeAsync(null, input.Code); if (flag) { var aa = input.MapTo <Customer>(); await _customerRepository.InsertAsync(aa); } else { throw new UserFriendlyException($"客户[{input.Code}]已存在!"); } }
protected async Task UpdateCustomerAsync(CustomerEditDto input) { var flag = await _customerManager.CheckCodeAsync(input.Id, input.Code); if (flag) { var entity = await _customerRepository.GetAsync(input.Id.Value); await _customerRepository.UpdateAsync(input.MapTo(entity)); } else { throw new UserFriendlyException($"客户[{input.Code}]已存在!"); } }
/// <summary> /// 用户modify /// </summary> /// <returns></returns> public async Task Modify(CustomerEditDto input) { if (!input.Password.Equals(input.RepeatPassword)) { throw new UserFriendlyException("两次密码不一致"); } var count = await _customerRepository.CountAsync(c => (c.Account.Equals(input.Account) || c.Email.Equals(input.Email)) && c.Id != input.Id.Value); if (count > 0) { throw new UserFriendlyException("该账户或邮箱已被注册,请重试"); } var model = input.MapTo <Customer>(); await _customerRepository.UpdateAsync(model); }
/// <summary> /// 客户注册 /// </summary> /// <returns></returns> public async Task Register(CustomerEditDto input) { if (!input.Password.Equals(input.RepeatPassword)) { throw new UserFriendlyException("两次密码不一致"); } var count = await _customerRepository.CountAsync(c => c.Account.Equals(input.Account) || c.Email.Equals(input.Email)); if (count > 0) { throw new UserFriendlyException("该账户或邮箱已被注册,请重试"); } var model = input.MapTo <Customer>(); await _customerRepository.InsertAsync(model); }
protected async Task CreateCustomerAsync(CustomerEditDto input) { await _customerRepository.InsertAsync(input.MapTo <Customer>()); }
public CreateOrUpdateCustomerViewModel(CustomerEditDto output) { output.MapTo(this); }
public CustomerViewModel(CustomerEditDto output) { output.MapTo(this); }