public async Task <TodoVO> Update(TodoVO obj) { try { var old = _context.Todo.Where(p => p.Id == obj.Id).FirstOrDefault(); if (old != null) { old.Category = obj.Category; old.StartDate = obj.StartDate; old.EndDate = obj.EndDate; old.TaskName = obj.TaskName; await _context.SaveChangesAsync(); return(obj); } else { return(null); } } catch (Exception ex) { _logger.LogInformation(string.Format("Error trying update object with id = {0}. Error message = {1}", obj.Id, ex.Message)); return(obj); } }
public async Task <ActionResult> Insert([FromBody] TodoVO obj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var item = _service.Insert(obj).Result; return(CreatedAtAction("Get", new { id = item.Id }, item)); }
public async Task <TodoVO> Update(TodoVO obj) { var old = _todo.Where(p => p.Id == obj.Id).FirstOrDefault(); old.Category = obj.Category; old.StartDate = obj.StartDate; old.EndDate = obj.EndDate; old.TaskName = obj.TaskName; return(obj); }
public Todo LoadModel(TodoVO vo) { return(new Todo() { Id = vo.Id, Category = vo.Category, CreatedDate = vo.CreatedDate, EndDate = vo.EndDate, StartDate = vo.StartDate, TaskName = vo.TaskName }); }
public void Insert_InvalidObjectPassed_ReturnsBadRequest() { var nameMissingItem = new TodoVO() { Id = Guid.Parse("6da0e0a9-143e-466e-b594-4ddb3d0fb5d3"), TaskName = "Dentist" }; _controller.ModelState.AddModelError("Category", "Required"); var badResponse = _controller.Insert(nameMissingItem).Result; Assert.IsType <BadRequestObjectResult>(badResponse); }
public void Insert_ValidObjectPassed_ReturnedResponseHasCreatedItem() { var testItem = new TodoVO() { Category = "Personal" }; var createdResponse = _controller.Insert(testItem).Result as CreatedAtActionResult; var item = createdResponse.Value as TodoVO; Assert.IsType <TodoVO>(item); Assert.Equal("Personal", item.Category); }
public async Task <TodoVO> Insert(TodoVO obj) { try { _context.Todo.Add(new Todo().LoadModel(obj)); await _context.SaveChangesAsync(); return(obj); } catch (Exception ex) { _logger.LogInformation(string.Format("Error trying insert new record with id = {0}. Error message = {1}", obj.Id, ex.Message)); return(null); } }
public void Insert_ValidObjectPassed_ReturnsCreatedResponse() { TodoVO item = new TodoVO() { Id = Guid.Parse("6da0e0a9-143e-466e-b594-4ddb3d0fb5d3"), Category = "Personal Appointment", CreatedDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2).AddHours(2), StartDate = DateTime.Now.AddDays(2).AddHours(1), TaskName = "Dentist" }; var createdResponse = _controller.Insert(item).Result; Assert.IsType <CreatedAtActionResult>(createdResponse); }
public void Update_ValidObjectPassed_ReturnedResponseHasCreatedItem() { var testItem = new TodoVO() { Id = Guid.Parse("6da0e0a9-143e-466e-b594-4ddb3d0fb5d3"), Category = "Personal Appointment", CreatedDate = DateTime.Now, EndDate = DateTime.Now.AddDays(2).AddHours(2), StartDate = DateTime.Now.AddDays(2).AddHours(1), TaskName = "Dentist" }; var createdResponse = _controller.Update(testItem).Result as CreatedAtActionResult; var item = createdResponse.Value as TodoVO; Assert.IsType <TodoVO>(item); Assert.Equal("Personal Appointment", item.Category); }
public async Task <ActionResult> Update(TodoVO obj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var item = _service.Update(obj).Result; if (item != null) { return(CreatedAtAction("Get", new { id = item }, item)); } else { return(NotFound()); } }
public async Task <TodoVO> Update(TodoVO obj) { return(await _todoRepository.Update(obj)); }
public async Task <TodoVO> Insert(TodoVO obj) { return(await _todoRepository.Insert(obj)); }
public async Task <TodoVO> Insert(TodoVO obj) { obj.Id = Guid.NewGuid(); _todo.Add(obj); return(obj); }