public async Task WillCreateNewItem() { // Arrange var item = new TodoItem { Name = "test", IsComplete = false, }; // Act var actual = await sut.Create(item); // Assert Assert.IsNotNull(actual.Key); }
public async Task <Guid> Create(string name) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Task name is null or empty"); } bool isCorrectLength = name.Length >= _MashAppConfig.MiminumTaskNameLength && name.Length <= _MashAppConfig.MaximumTaskNameLength; if (!isCorrectLength) { throw new ArgumentException($"Name of the task is either too short or too long. Actual value = {name.Length}, Expected value has to be be between 3 and 50"); } var item = new TodoItem { Id = Guid.NewGuid(), ModifiedAt = DateTimeOffset.Now, Name = name, Status = TodoStatus.Open }; await _Repository.Create(item); _StatisticsRepository.RaiseCreatedCount(); return(item.Id); }
public TodoItemGetViewModel Create(TodoItemCreateViewModel value) { TodoItem item = new TodoItem { Content = value.Content, CreatedAt = DateTime.Now }; var model = _repository.Create(item); var viewmodel = _mapper.Map <TodoItemGetViewModel>(model); return(viewmodel); }
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 async Task <TodoItem> Create(TodoItem item) { try { var result = await todoItemRepository.Create(item); return(result); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <JsonResult> Post([FromBody] TodoItem newTodoItem) { //TODO: Validate model coming in better than this! if (newTodoItem != null) { _todoRepo.Create(newTodoItem); var changes = await _unitOfWork.SaveChangesAsync(); Response.StatusCode = (int)HttpStatusCode.Created; Response.Headers["Location"] = $"/api/Todo/{newTodoItem.Id}"; //TODO: Gonz do this properly... all api items should provide valid urls. return(Json("Item saved successfully")); } else { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json("No item was passed to create")); } }
public OperationDetails CreateTodoItem(TodoItemDTO todoItem) { var todoItemEntity = new TodoItemEntity { TodoListEntityId = todoItem.TodoListEntityId, Name = todoItem.Name, Note = todoItem.Note, IsCompleted = false }; bool normalizationRequired; todoItemEntity.OrderNumber = GetToDoItemOrderingNumber(todoItemEntity.TodoListEntityId, -1, out normalizationRequired); _todoItemRepository.Create(todoItemEntity); db.Commit(); if (normalizationRequired) { NormalizeToDoItemOrderingNumbers(); } return(new OperationDetails(true, "TodoItem успешно добавлен", "")); }
public async Task <IActionResult> Create([Bind("Id,Details,IsComplete,Name")] TodoItem todoItem) { try { if (ModelState.IsValid) { _todoItemRepo.Create(todoItem); var changes = await _unitOfWork.SaveChangesAsync(); return(RedirectToAction("Index")); } else { throw new Exception("ModelState Invalid"); } } catch { return(View(todoItem)); } }
public async Task <bool> Create(TodoItem item) { await _repository.Create(item).ConfigureAwait(false); return(await _unitOfWork.Save().ConfigureAwait(false)); }