示例#1
0
 public IActionResult UpdateOwner(Guid id, [FromBody] ProgramForUpdateDto Program)
 {
     try
     {
         if (Program == null)
         {
             _logger.LogError("Program object sent from client is null.");
             return(BadRequest("Program object is null"));
         }
         if (!ModelState.IsValid)
         {
             _logger.LogError("Invalid Program object sent from client.");
             return(BadRequest("Invalid model object"));
         }
         var ProgramEntity = _repository.Programs.GetProgramById(id);
         if (ProgramEntity == null)
         {
             _logger.LogError($"Program with id: {id}, hasn't been found in db.");
             return(NotFound());
         }
         _mapper.Map(Program, ProgramEntity);
         _repository.Programs.UpdateProgram(ProgramEntity);
         _repository.Save();
         return(NoContent());
     }
     catch (Exception ex)
     {
         _logger.LogError($"Something went wrong inside UpdateOwner action: {ex.Message}");
         return(StatusCode(500, "Internal server error"));
     }
 }
示例#2
0
        public async Task <ActionResult> UpdateProgram(int collegeId, int id, [FromBody] ProgramForUpdateDto program)
        {
            if (program == null)
            {
                return(BadRequest());
            }

            if (program.Description == program.Name)
            {
                ModelState.AddModelError("Description", "The provided description should be different from the name.");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!await _studyRouteRepository.CollegeExists(collegeId))
            {
                return(NotFound());
            }

            Programs oldProgramEntity = await _studyRouteRepository.GetProgramForCollege(collegeId, id);

            if (oldProgramEntity == null)
            {
                return(NotFound());
            }

            _mapper.Map(program, oldProgramEntity);


            if (!await _studyRouteRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(NoContent());
        }