public void Create_ValidData_TodoItem() { //Arrange var item = new TodoItem() { Name = "Todo 5", Priority = Priority.CRITICAL }; //Act var data = _todoItemService.Create(item); //Assert Assert.NotEqual(Guid.Empty, data.Id); }
public IActionResult Post([FromBody] TodoItemCreateViewModel value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TodoItemGetViewModel model = _service.Create(value); return(CreatedAtRoute("DefaultApi", new { model.Id }, model)); }
public async Task <IActionResult> Create(TodoItem model) { if (!ModelState.IsValid) { return(View(model)); } await _todoItemService.Create(model.Text, User); return(RedirectToAction("Index")); }
async Task AddTodoItem(TodoItem item) { try { var addedItem = await todoItemService.Create(item); TodoItems.Add(addedItem); } catch (Exception ex) { // TODO: show alert Debug.WriteLine(ex); } }
public async Task <Models.GetModel> Post([FromBody] PostModel model) { var item = await _todoItemService.Create(new CreateModel { Description = model.Description, DueDate = model.DueDate }); return(new Models.GetModel { Description = item.Description, DueDate = item.DueDate, Id = item.Id }); }
public void Handle(CreateTodoItemCommand command) { if (_todoItemService.Read(x => x.Description == command.Description).Any()) { command.AddNotification("Description", "Já existe uma tarefa com essa descrição."); } if (command.Invalid) { return; } var todoItem = new TodoItem { Description = command.Description, IsCompleted = command.IsCompleted }; _todoItemService.Create(todoItem); }
public IActionResult Create(int userId, int todoListId, TodoItemCreateVm todoItemCreateVm) { var todoList = _todoListService.Get(userId, todoListId); if (todoList == null) { return(NotFound()); } var todoItem = _mapper.Map <TodoItem>(todoItemCreateVm); todoItem.TodoList = todoList; _todoItemService.Create(todoItem); return(CreatedAtRoute( "GetTodoItem", new { userId = todoList.User.Id, todoListId = todoList.Id, todoItemId = todoItem.Id }, todoItem.Id)); }
public IActionResult Create(TodoItem item) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrors())); } try { _todoItemService.Create(item); _rabbitMQService.SendCreate(item); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok("Item successfully added to list.")); }
public async Task <ActionResult <TodoItem> > CreateTodoItem([FromBody] TodoItemToCreate model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(UnprocessableEntity(ModelState)); } var entity = _mapper.Map <Domain.Models.TodoItem>(model); if (!await _service.Create(entity)) { throw new ApiException("Creation of todo item failed on save."); } return(CreatedAtRoute(nameof(GetTodoItem), new { entity.Id }, _mapper.Map <TodoItem>(entity))); }
protected virtual async Task <IActionResult> DoCreate(TodoItemViewModel viewModel, string createdUrlPath) { var user = await this.GetLocalUser(UserService); await Validate(viewModel, user.Id); if (!ModelState.IsValid) { return(ValidationProblem()); } var todoItem = await TodoItemService.Create(user, viewModel.ToDto()); var responseBody = new { Message = StatusMessageLocalizer["TodoItemCreated"].Value, Data = todoItem.ToDto() }; return(Created($"{createdUrlPath}/{todoItem.Slug}", responseBody)); //return CreatedAtAction(nameof(View), ControllerContext.ActionDescriptor.ControllerName, new { slug = todoItem.Slug }, responseBody); }
public async Task WillCreateNewItem() { // Arrange var key = Guid.NewGuid().ToString(); var item = new TodoItem { Name = "test", IsComplete = false, }; var expected = item; expected.Key = key; todoItemRepository.Create(item).Returns(expected); // Act var actual = await sut.Create(item); // Assert Assert.AreEqual(actual, expected); }
public void Post([FromBody] TodoItemDto todo) { service.Create(todo); }
public async Task <IBaseCommandResult> HandleCreate(TodoItem item) { await _todoItemService.Create(item); return(new BaseCommandResult(true, "TodoItem created with Success!", ItemToDto(item))); }
public ActionResult <TodoItemRetrieve> Create(TodoItemCreate todoItem) { var createdItem = _itemService.Create(todoItem); return(CreatedAtRoute("GetTodoItem", new { id = createdItem.Id.ToString() }, createdItem)); }