Exemple #1
0
        public async Task <DepartmentResponseModel> UpdateAsync(Guid id, DepartmentUpdateModel model)
        {
            var newDepartment     = _mapper.Map <Department>(model);
            var updatedDepartment = await _departmentService.UpdateAsync(id, newDepartment);

            return(_mapper.Map <DepartmentResponseModel>(updatedDepartment));
        }
Exemple #2
0
        public async Task <IActionResult> Put(Guid id, DepartmentUpdateModel model)
        {
            var updatedDepartment = await _departmentService.UpdateAsync(id, model);

            var response = new Response(updatedDepartment);

            return(Ok(response));
        }
        public async Task <IActionResult> UpdateAsync(DepartmentUpdateModel department)
        {
            var result = await
                         _manager
                         .UpdateAsync(department);

            return(Ok(result
                ? ServiceResponseHelper.GetSuccessResponse(result)
                : ServiceResponseHelper.GetFailureResponse <bool>()));
        }
        public async Task <IResultModel> Update(DepartmentUpdateModel model)
        {
            var entity = await _repository.GetAsync(model.Id);

            if (entity == null)
            {
                return(ResultModel.NotExists);
            }

            _mapper.Map(model, entity);

            if (await _repository.Exists(entity))
            {
                return(ResultModel.HasExists);
            }

            var result = await _repository.UpdateAsync(entity);

            return(ResultModel.Result(result));
        }
Exemple #5
0
        public async Task <IResultModel> Update(DepartmentUpdateModel model)
        {
            var entity = await _repository.GetAsync(model.Id);

            if (entity == null)
            {
                return(ResultModel.NotExists);
            }

            _mapper.Map(model, entity);

            if (await _repository.ExistsName(entity.Name, entity.ParentId, entity.Id))
            {
                return(ResultModel.Failed("所属部门中已存在名称相同的部门"));
            }
            if (model.Code.NotNull() && await _repository.ExistsCode(entity.Code, entity.Id))
            {
                return(ResultModel.Failed("编码已存在"));
            }

            entity.FullPath = entity.Name;
            //查询父级
            if (model.ParentId.NotEmpty())
            {
                var parent = await _repository.GetAsync(model.ParentId);

                if (parent != null)
                {
                    //设置完整路径
                    entity.FullPath = $"{parent.FullPath}/{entity.Name}";
                }
            }
            var result = await _repository.UpdateAsync(entity);

            if (result)
            {
                await ClearCache();
            }
            return(ResultModel.Result(result));
        }
        public async Task <bool> UpdateAsync(DepartmentUpdateModel department)
        {
            var departmentDB =
                await
                _dataContext
                .Departments
                .FirstOrDefaultAsync(x => x.Id.Equals(department.Id));

            if (departmentDB == null)
            {
                return(false);
            }

            departmentDB.Name = department.Name;

            _dataContext
            .Departments
            .Update(departmentDB);
            await _dataContext.SaveChangesAsync();

            return(true);
        }
Exemple #7
0
 public Task <IResultModel> Update(DepartmentUpdateModel model)
 {
     return(_service.Update(model));
 }