コード例 #1
0
        public IActionResult Update(DepartmentForUpdateDto departmentForUpdateDto)
        {
            var result = departmentService.Update(departmentForUpdateDto);

            if (result.Success)
            {
                return(NoContent());
            }
            return(BadRequest(result.Message));
        }
コード例 #2
0
        public IResult Update(DepartmentForUpdateDto departmentForUpdateDto)
        {
            var department = GetById(departmentForUpdateDto.Id).Data;

            department.Description = departmentForUpdateDto.Description;
            department.Name        = departmentForUpdateDto.Name;
            department.UpdatedAt   = DateTime.Now;

            departmentDal.Update(department);
            return(new SuccessResult(Messages.DepartmentUpdated));
        }
コード例 #3
0
        public async Task <IActionResult> UpdateDepartment(Guid id, DepartmentForUpdateDto departmentForUpdateDto)
        {
            var depFromRepo = await _depRepo.GetDepartment(id);

            _mapper.Map(departmentForUpdateDto, depFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating department {id} failed on save");
        }
コード例 #4
0
        public void Update_WhenUpdatedDepartment_ShouldUpdate()
        {
            // Arrange
            var departmentForUpdateDto = new DepartmentForUpdateDto();
            var mockDepartmentDal      = new MockDepartmentDal().MockUpdate().MockGet(new Department());
            var sut = new DepartmentManager(mockDepartmentDal.Object);

            // Act
            sut.Update(departmentForUpdateDto);

            // Assert
            mockDepartmentDal.VerifyUpdate(Times.Once());
        }
コード例 #5
0
        public async Task <IActionResult> AddDepartment(DepartmentForUpdateDto departmentForUpdateDto)
        {
            var depToCreate = _mapper.Map <Department>(departmentForUpdateDto);

            _repo.Add(depToCreate);

            if (await _repo.SaveAll())
            {
                return(Ok(depToCreate));
            }



            return(BadRequest());
            //return Ok();
        }
コード例 #6
0
        public static async Task Update(DepartmentForUpdateDto departmentForUpdateDto)
        {
            using var client = new HttpClient();
            var uri = $"{APIAddresses.DepartmentService}/{departmentForUpdateDto.Id}";

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", FormAccessToken.Token);
            var response = await client.PutAsJsonAsync(uri, departmentForUpdateDto);

            if (response.IsSuccessStatusCode)
            {
                return;
            }

            var errorContent = response.Content.ReadFromJsonAsync <ErrorDetail>().Result;

            throw new HttpFailureException(errorContent);
        }
コード例 #7
0
        public void DepartmentForUpdateValidator_TrueStory()
        {
            // Arrange
            var model = new DepartmentForUpdateDto()
            {
                Id          = 1,
                Description = "Desc Department T",
                Name        = "Department T"
            };
            var sut = new DepartmentForUpdateValidator();

            // Act
            var result = sut.TestValidate(model);

            // Assert
            result.ShouldNotHaveAnyValidationErrors();
        }
コード例 #8
0
        public async Task <IActionResult> UpdateDepartment(int userId, string deptName, DepartmentForUpdateDto departmentForUpdateDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var departmentFromRepo = await _repo.GetDepartment(userId, deptName);

            _mapper.Map(departmentForUpdateDto, departmentFromRepo);

            if (await _repo.SaveAll())
            {
                return(CreatedAtRoute("GetDepartment", new { deptName = departmentFromRepo.DeptName, userId = userId }, departmentFromRepo));
            }

            throw new Exception($"Updating department {deptName} failed on save");
        }