public async Task <IActionResult> Post([FromBody] EntitiesG.EntitiesRev.Task task) { if (ModelState.IsValid) { try { var addedTask = _repo.Create(task); return(Ok(addedTask)); } catch (Exception) { throw; } } return(BadRequest("Failed to save changes to the database")); }
public async Task <IActionResult> Put(int id, [FromBody] EntitiesG.EntitiesRev.Task task) { if (ModelState.IsValid) { try { var taskFromRepo = await _repo.GetById(id); taskFromRepo.TaskName = task.TaskName ?? taskFromRepo.TaskName; taskFromRepo.Phase = task.Phase ?? taskFromRepo.Phase; taskFromRepo.PhaseId = task.PhaseId != 0 ? task.PhaseId : taskFromRepo.PhaseId; var taskUpdated = _repo.Update(taskFromRepo.TaskId, taskFromRepo); return(Ok(taskUpdated)); } catch (Exception) { _logger.LogError($"Thrown exception when updating"); BadRequest("Something when wrong while updating"); } } return(BadRequest("Error occured")); }