public IActionResult UpdateTodoList(int id, [FromBody] ListCreateDto todoList) { try { if (todoList == null) { return(BadRequest(new { message = "Owner object is null" })); } if (!ModelState.IsValid) { _logger.LogError("Invalid owner object sent from client"); return(BadRequest(new { message = "Invalid model object" })); } var todoListEntity = _repository.TodoList.GetTodoListById(id); if (todoListEntity == null) { _logger.LogError($"Owner id: {id} is not found in db"); return(NotFound()); } var a = _repository.TodoList.GetTodoListTitle(todoList.ActivityTitle); if (a != null) { return(BadRequest(new { message = $"we alredy have category {todoList.ActivityTitle} in our db, cannot have same category" })); } _mapper.Map(todoList, todoListEntity); _repository.TodoList.UpdateTodoList(todoListEntity); _repository.Save(); return(NoContent()); } catch (Exception ex) { _logger.LogInfo($"There is something wrong with UpdateTodoCategory {ex.Message}"); return(StatusCode(500, "Internal Server Error")); } }
public IActionResult CreateTodoList([FromBody] ListCreateDto todoList) { try { if (todoList == null) { _logger.LogError($"TodoCategory Object Cannot be Null"); return(BadRequest(new { message = "TodoCategory Object Cannot Be Null" })); } if (!ModelState.IsValid) { _logger.LogError($"TodoCategory object you input is not valid"); return(BadRequest(new { message = "TodoCategory object from client is not valid" })); } var a = _repository.TodoList.GetTodoListTitle(todoList.ActivityTitle); if (a != null) { return(BadRequest(new { message = $"we alredy have category {todoList.ActivityTitle} in our db, cannot have same category" })); } var todoListEntity = _mapper.Map <TodoList>(todoList); _repository.TodoList.CreateTodoList(todoListEntity); _repository.Save(); var createdTodoList = _mapper.Map <TodoListDTO>(todoListEntity); _logger.LogInfo($"Create new TodoCategory: {createdTodoList}"); return(CreatedAtRoute("TodoCategoryById", new { id = createdTodoList.TodoID }, createdTodoList)); } catch (Exception ex) { _logger.LogError($"There is something wrong with CreateTodoCategory {ex.Message}"); return(StatusCode(500, "Internal Server Error")); } }