public bool Update(ScheduleItemForUpdateDto scheduleItemForUpdate) { try { var scheduleItemDto = GetById(scheduleItemForUpdate.id); if (scheduleItemDto == null) { return(false); } ScheduleItem DataEntity = _mapper.Map <ScheduleItem>(scheduleItemDto); _mapper.Map(scheduleItemForUpdate, DataEntity); _repository.Update(DataEntity); _repository.Save(); _logger.LogError($"Updated ScheduleItem with id: {DataEntity.id}"); return(true); } catch (Exception ex) { _logger.LogError($"Something went wrong inside UpdateScheduleItem action: {ex.Message}"); throw new Exception(); } }
public IActionResult UpdateScheduleItem([FromBody] ScheduleItemForUpdateDto scheduleItem) { try { if (scheduleItem == null) { _logger.LogError("ScheduleItem object sent from client is null."); return(BadRequest("ScheduleItem object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid ScheduleItem object sent from client."); return(BadRequest("Invalid model object")); } bool succes = _scheduleItemLogic.Update(scheduleItem); if (!succes) { return(NotFound()); } return(Ok("ScheduleItem is updated")); } catch (Exception ex) { return(StatusCode(500, "Internal server error")); } }
public async Task <HttpResponseMessage> UpdateScheduleItemAsync(int scheduleId, int scheduleItemId, ScheduleItemForUpdateDto scheduleItem) { return(await _httpService.Put($"api/schedules/{scheduleId}/scheduleItems/{scheduleItemId}", scheduleItem)); }
public async Task <IActionResult> UpdateScheduleItem(int scheduleId, int scheduleItemId, ScheduleItemForUpdateDto scheduleItem) { try { var userId = int.Parse(User.FindFirst("id").Value); if (!await _schedulesRepository.ScheduleExistsAsync(userId, scheduleId)) { return(NotFound()); } if (await _scheduleItemsRepository.DatesConflictAsync(scheduleId, scheduleItem.DayOfWeek, scheduleItem.StartTime, scheduleItem.EndTime, scheduleItemId)) { return(Conflict()); } var scheduleItemFromRepo = await _scheduleItemsRepository.GetScheduleItemAsync(scheduleId, scheduleItemId); if (scheduleItemFromRepo == null) { return(NotFound()); } _mapper.Map(scheduleItem, scheduleItemFromRepo); scheduleItemFromRepo.Color = _scheduleItemsRepository.GetScheduleItemColor(scheduleItem.TypeOfClasses); _scheduleItemsRepository.UpdateScheduleItem(scheduleItemFromRepo); if (await _dbRepository.SaveChangesAsync()) { return(NoContent()); } } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }