public IActionResult UpdateSchedule([FromBody] ScheduleForUpdateDto schedule) { try { if (schedule == null) { _logger.LogError("Schedule object sent from client is null."); return(BadRequest("Schedule object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid Schedule object sent from client."); return(BadRequest("Invalid model object")); } bool succes = _scheduleLogic.Update(schedule); if (!succes) { return(NotFound()); } return(Ok("Schedule is updated")); } catch (Exception ex) { return(StatusCode(500, "Internal server error")); } }
public bool Update(ScheduleForUpdateDto scheduleForUpdate) { try { var scheduleDto = GetById(scheduleForUpdate.id); if (scheduleDto == null) { return(false); } Schedule DataEntity = _mapper.Map <Schedule>(scheduleDto); _mapper.Map(scheduleForUpdate, DataEntity); _repository.Update(DataEntity); _repository.Save(); _logger.LogError($"Updated Schedule with id: {DataEntity.id}"); return(true); } catch (Exception ex) { _logger.LogError($"Something went wrong inside UpdateSchedule action: {ex.Message}"); throw new Exception(); } }
public async Task <IActionResult> UpdateSchedule(int scheduleId, ScheduleForUpdateDto schedule) { try { var userId = int.Parse(User.FindFirst("id").Value); if (await _schedulesRepository.ScheduleExistsAsync(userId, schedule.Name)) { return(Conflict()); } var scheduleFromRepo = await _schedulesRepository.GetScheduleAsync(userId, scheduleId); if (scheduleFromRepo == null) { return(NotFound()); } _mapper.Map(schedule, scheduleFromRepo); _schedulesRepository.UpdateSchedule(scheduleFromRepo); if (await _dbRepository.SaveChangesAsync()) { return(NoContent()); } } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }
public IActionResult UpdateSchedule(int systemId, [FromBody] ScheduleForUpdateDto scheduleForUpdate) { var system = _unitOfWork.IrigationSystemRepository.ExistIrigationSystem(systemId); if (!system) { return(BadRequest("Irrigation system not found")); } var schedule = _unitOfWork.ScheduleRepository.GetSchedule(systemId); if (schedule != null) { schedule.TemperatureMin = scheduleForUpdate.TemperatureMin; schedule.TemperatureMax = scheduleForUpdate.TemperatureMax; schedule.Start = scheduleForUpdate.Start; schedule.Stop = scheduleForUpdate.Stop; _unitOfWork.ScheduleRepository.Update(schedule); } else { var scheduleForCreation = _mapper.Map <Schedule>(scheduleForUpdate); _unitOfWork.ScheduleRepository.Create(scheduleForCreation); } if (!_unitOfWork.Save()) { return(StatusCode(500, "A problem happened with handling your request. Try again!")); } if (schedule != null) { return(NoContent()); } return(StatusCode(201)); }
public async Task <HttpResponseMessage> UpdateScheduleAsync(int scheduleId, ScheduleForUpdateDto schedule) { return(await _httpService.Put($"api/schedules/{scheduleId}", schedule)); }