Exemplo n.º 1
0
        public async Task <IActionResult> AddItem(NewToDoItem newItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var succesfull = await _toDoItemService.AddItemAsync(newItem);

            if (!succesfull)
            {
                return(BadRequest(new { error = "Could not add item" }));
            }
            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <bool> AddItemAsync(NewToDoItem newToDoItem)
        {
            var entity = new ToDoItem
            {
                Id     = Guid.NewGuid(),
                IsDone = false,
                Title  = newToDoItem.Title,
                DueAt  = DateTimeOffset.Now.AddDays(3)
            };

            _context.Items.Add(entity);
            var saveResult = await _context.SaveChangesAsync();

            return(saveResult == 1);
        }
        public async Task <bool> AddItemAsync(NewToDoItem newToDoItem, ApplicationUser currentUser)
        {
            var entity = new ToDoItem
            {
                Id      = Guid.NewGuid(),
                IsDone  = false,
                Title   = newToDoItem.Title,
                DueAt   = newToDoItem.DueAt,
                OwnerId = currentUser.Id
            };

            _context.Items.Add(entity);
            var saveResult = await _context.SaveChangesAsync();

            return(saveResult == 1);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> AddItem(NewToDoItem toDoItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var success = await _toDoItemService.AddItemAsync(toDoItem);

            if (!success)
            {
                return(BadRequest(new
                {
                    error = "Failed to add the item."
                }));
            }

            return(Ok());
        }
Exemplo n.º 5
0
        public void WhenAddingAnItemToAList()
        {
            ToDoList    mappedList      = new ToDoList();
            string      itemName        = "Do something awesome";
            NewToDoItem newToDoItemData = new NewToDoItem
            {
                ListId      = listId.ToString(),
                NewItemName = itemName
            };

            GetMock <IRepository>().Setup(x => x.AddItem(Any <string>(), Any <string>(), Any <string>())).Returns(toDoListData);
            GetMock <IMapper>().Setup(x => x.MapToDoList(Any <ToDoListDataModel>())).Returns(mappedList);

            var actual = classUnderTest.AddItem(userId, newToDoItemData);

            GetMock <IRepository>().Verify(x => x.AddItem(userId, listId.ToString(), itemName));
            GetMock <IMapper>().Verify(x => x.MapToDoList(toDoListData));

            Assert.That(actual, Is.SameAs(mappedList));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> AddItem(NewToDoItem newItem)
        {
            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var succesfull = await _toDoItemService.AddItemAsync(newItem, currentUser);

            if (!succesfull)
            {
                return(BadRequest(new { error = "Could not add item" }));
            }
            return(Ok());
        }
 public Task AddItemAsync(NewToDoItem newToDoItem, object currentUser)
 {
     throw new NotImplementedException();
 }
 public Task AddItemAsync(NewToDoItem newToDoItem)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 9
0
        public ToDoList AddItem(string userId, NewToDoItem item)
        {
            var listData = _repository.AddItem(userId, item.ListId, item.NewItemName);

            return(_mapper.MapToDoList(listData));
        }
Exemplo n.º 10
0
 public async Task <bool> AddItemAsync(NewToDoItem toDoItem)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
        public ToDoList AddItem(NewToDoItem item)
        {
            var userId = Request.Cookies["user"];

            return(_facade.AddItem(userId, item));
        }