コード例 #1
0
        public async Task <IActionResult> UpdateProject(int id, [FromBody] ProjectBaseDto dto)
        {
            try
            {
                if (dto == null || id == 0)
                {
                    return(BadRequest());
                }

                var exists = await _sdlcSystemAppService.CheckSdlcSystemExists(dto.SdlcSystemId);

                if (!exists)
                {
                    return(NotFound());
                }

                var conflictSystem = await _projectAppService.CheckForConflictingSystem(dto.SdlcSystemId, id);

                if (conflictSystem && string.IsNullOrWhiteSpace(dto.ExternalId) &&
                    string.IsNullOrWhiteSpace(dto.Name))
                {
                    return(Conflict());
                }

                var conflictExternalId = await _projectAppService.CheckForConflictingExternalId(dto.ExternalId, id);

                if (conflictExternalId && dto.SdlcSystemId == 0 &&
                    string.IsNullOrWhiteSpace(dto.Name))
                {
                    return(Conflict());
                }

                var result = await _projectAppService.UpdateProject(id, dto);

                if (!result.Value)
                {
                    return(NotFound());
                }

                if (result == null)
                {
                    return(StatusCode(500, "A problem occurred while handling your request."));
                }

                return(Ok());//We have also the option to return NoContent(); instead, for update usually, successfull request that shouldn't return anything
            }
            catch (Exception ex)
            {
                _log4net.Info(ex.Message, ex);
                return(StatusCode(500));
            }
        }