public async Task <IActionResult> UpdatePomodoro(Guid id, [FromBody] PomodoroDTO pomodoroDto) { try { if (!ModelState.IsValid) { _logger.LogError("Invalid pomodoro object sent from a client."); return(BadRequest("Invalid model object")); } var pomodoro = await _repository.Pomodoro.GetPomodoroById(id); //ToDo: Map pomodoro.Id = id; pomodoro.FinishTime = pomodoroDto.FinishTime; pomodoro.Description = pomodoroDto.Description != "" ? pomodoroDto.Description : pomodoro.Description; // await _repository.Pomodoro.Update(pomodoro); await _repository.SaveAsync(); return(Ok()); } catch (Exception ex) { _logger.LogError($"Something went wrong inside UpdatePomodoro action. {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public async Task <IActionResult> CreatePomodoro(string id, [FromBody] PomodoroDTO pomodoroDTO) { try { if (pomodoroDTO == null) { _logger.LogError("Owner pomodoro sent from client is null."); return(BadRequest("Pomodoro object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid pomodoro object sent from a client."); return(BadRequest("Invalid model object")); } var pomodoro = _mapper.Map <Pomodoro>(pomodoroDTO); pomodoro.Id = Guid.NewGuid(); var currentsUser = await _repository.User.GetUserByExternalId(id); pomodoro.UserId = currentsUser.Id; await _repository.Pomodoro.CreatePomodoro(pomodoro); await _repository.SaveAsync(); _logger.LogInfo($"Created a Pomodoro with id: {pomodoro.Id}"); return(Ok(pomodoro.Id)); } catch (Exception ex) { _logger.LogError($"Something went wrong inside CreatePomodoro action. {ex.Message}"); return(StatusCode(500, "Internal server error")); } }