public async Task <IActionResult> Create([Bind("Title,Color")] ToDoItemCreateModel toDoItem) { if (ModelState.IsValid) { await _toDo.AddAsync(new Item <Guid, string> { Color = toDoItem.Color, Title = toDoItem.Title }); return(RedirectToAction(nameof(Index))); } return(View(toDoItem)); }
public async Task <ActionResult <ToDoItemViewModel> > Post(ToDoItemCreateModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var toDoItemObj = _mapper.Map <ToDoItem>(model); _context.ToDoItems.Add(toDoItemObj); await _context.SaveChangesAsync(); var createdToDoItem = await _context.ToDoItems.FindAsync(toDoItemObj.Id); var mappedItem = _mapper.Map <ToDoItemViewModel>(createdToDoItem); return(Ok(mappedItem)); }
public async Task <IActionResult> CreateItem(ToDoItemCreateModel createModel) { _logger.LogInformation("CreateItem() calles"); if (string.IsNullOrWhiteSpace(createModel.Title) || string.IsNullOrWhiteSpace(createModel.Description)) { return(new BadRequestObjectResult("tile and description must contain content")); } var newItem = new ToDoItem { Id = Guid.NewGuid(), Title = createModel.Title, Description = createModel.Description }; await _database.Add(newItem); var readModel = ToReadModel(newItem); return(Created(nameof(readModel), readModel)); }