Exemple #1
0
 public async Task CreateOrUpdate(BusinessDepartmentDto input)
 {
     if (input.Id.HasValue)
     {
         await UpdateAsync(input);
     }
     else
     {
         await CreateAsync(input);
     }
 }
Exemple #2
0
        private async Task UpdateAsync(BusinessDepartmentDto input)
        {
            if (_businessDepartmentRepository.GetAll().Where(p => p.Name == input.Name && p.Id != input.Id.Value).Count() > 0)
            {
                throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "该名称已经存在");
            }
            var model = await _businessDepartmentRepository.GetAsync(input.Id.Value);

            model.Name         = input.Name;
            model.Code         = input.Code;
            model.ContactUser  = input.ContactUser;
            model.ContactTel   = input.ContactTel;
            model.Address      = input.Address;
            model.Email        = input.Email;
            model.Phone        = input.Phone;
            model.CreationTime = input.CreationTime;
            model.InputCode1   = model.Name.ToChineseSpell().ToLower();
            model.InputCode2   = model.Name.ToChineseSpell().ToLower();
            await _businessDepartmentRepository.UpdateAsync(model);
        }
Exemple #3
0
        private async Task CreateAsync(BusinessDepartmentDto input)
        {
            if (_businessDepartmentRepository.GetAll().Where(p => p.Name == input.Name).Count() > 0)
            {
                throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "该名称已经存在");
            }
            var model = new BusinessDepartment();

            model.Name         = input.Name;
            model.Code         = input.Code;
            model.ContactUser  = input.ContactUser;
            model.ContactTel   = input.ContactTel;
            model.Address      = input.Address;
            model.Email        = input.Email;
            model.Phone        = input.Phone;
            model.CreationTime = DateTime.Now;
            model.InputCode1   = model.Name.ToChineseSpell().ToLower();
            model.InputCode2   = model.Name.ToChineseSpell().ToLower();
            await _businessDepartmentRepository.InsertAsync(model);

            await CurrentUnitOfWork.SaveChangesAsync(); //It's done to get Id of the edition.
        }