Пример #1
0
        public async Task <IActionResult> UpdateDepartmentAsync(int id, [FromBody] DepartmentModelRq model)
        {
            if (!ModelState.IsValid)
            {
                Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection modelErrors = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection();
                foreach (var entry in ModelState.Values)
                {
                    foreach (var error in entry.Errors)
                    {
                        modelErrors.Add(error);
                    }
                }
                return(BadRequest(modelErrors));
            }
            var issuer = GetCurrentUserIdentity <int>();

            try
            {
                return(Ok(await _departmentService.UpdateDepartmentAsync(id, model, issuer)));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Пример #2
0
 public async Task <int> CreateDepartmentAsync(DepartmentModelRq model, UserIdentity <int> issuer)
 {
     try
     {
         var entity = _mapper.Map <Department>(model);
         _departmentRepository.Create(entity);
         entity.CreateBy(issuer).UpdateBy(issuer);
         if (await _uow.SaveChangesAsync() == 1)
         {
             return(entity.Id);
         }
         return(0);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #3
0
        public async Task <bool> UpdateDepartmentAsync(int id, DepartmentModelRq model, UserIdentity <int> issuer)
        {
            try
            {
                var entity = await _departmentRepository.GetEntityByIdAsync(id);

                if (entity == null)
                {
                    return(false);
                }
                _mapper.Map(model, entity);
                entity.UpdateBy(issuer);
                _departmentRepository.Update(entity);
                if (await _uow.SaveChangesAsync() == 1)
                {
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                throw e;
            }
        }