public async Task UpdateToDoItem() { ToDoItemDto updatedToDoItem = await _toDoItemRepository.Update(new UpdateToDoItemDto { ToDoItemId = 2, Description = "sell phone", UserId = 1, LabelId = 1, ToDoListId = 1 }); Assert.IsNotNull(updatedToDoItem); Assert.AreEqual("sell phone", updatedToDoItem.Description); }
public void UpdateItem(ToDoItem updatedItem) { ToDoItemRepository toDoItemRepository = new ToDoItemRepository(); updatedItem.itemStatus = Status.Completed.ToString(); toDoItemRepository.Update(updatedItem); }
public async Task <ToDoItemViewModel> Handle(UpdateToDoItemStatusCommand request, CancellationToken cancellationToken) { var toDoItem = await ToDoItemRepository.Get(request.Id); if (toDoItem == null) { throw new NotFoundException(request.Id, typeof(ToDoItem)); } toDoItem.IsComplete = request.IsComplete; var updateResponse = await ToDoItemRepository.Update(toDoItem); var viewModel = new ToDoItemViewModel(updateResponse); return(viewModel); }
public ActionResult Sort() { string ids = Request.Form["ids"]; string[] sorted = ids.Split(','); List <long> l = new List <long>(); foreach (string id in sorted) { long temp = 0; if (long.TryParse(id.Replace("item", ""), out temp)) { l.Add(temp); } } long accountId = MTApp.CurrentRequestContext.CurrentAdministrator(MTApp).Id; ToDoItemRepository repository = new ToDoItemRepository(MTApp.CurrentRequestContext); List <ToDoItem> items = repository.FindByAccountId(accountId); repository.AutoSubmit = false; int currentSort = 1; foreach (long itemid in l) { foreach (ToDoItem item in items) { if (item.Id == itemid) { item.SortOrder = currentSort; currentSort += 1; repository.Update(item); } } } repository.SubmitChanges(); return(new JsonResult() { Data = "result:true" }); }
public ActionResult Toggle(long id) { bool success = false; try { long accountId = MTApp.CurrentRequestContext.CurrentAdministrator(MTApp).Id; ToDoItemRepository repository = new ToDoItemRepository(MTApp.CurrentRequestContext); ToDoItem item = repository.Find(id); if (item != null) { if (item.AccountId == accountId) { item.IsComplete = !item.IsComplete; success = repository.Update(item); } } } catch { } return(new RedirectResult("~/todo")); }
public void ToDoItemRepository_Update_ShouldReturnUpdatedEntity() { var list = new Order(); var itemToChange = new ToDoItem() { Id = 1, DateAdded = DateTime.MinValue, DateCompletion = default(DateTime), IsCompleted = false, IsFavourited = false, List = list, Note = "note", Text = "text" }; var dbData = new List<ToDoItem>() { itemToChange, new ToDoItem() { Id = 2, DateAdded = DateTime.MinValue, DateCompletion = default(DateTime), IsCompleted = false, IsFavourited = false, List = new Order(), Note = "note", Text = "text" }, new ToDoItem() { Id = 3, DateAdded = DateTime.MinValue, DateCompletion = default(DateTime), IsCompleted = false, IsFavourited = false, List = new Order(), Note = "note", Text = "text" } }.AsQueryable(); var newItem = new ToDoItem() { Id = 1, DateAdded = DateTime.MinValue, DateCompletion = default(DateTime), IsCompleted = false, IsFavourited = false, List = null, Note = "note1", Text = "text1" }; var dbSetMock = new Mock<DbSet<ToDoItem>>(); dbSetMock.As<IQueryable<ToDoItem>>().Setup(x => x.Provider).Returns(dbData.Provider); dbSetMock.As<IQueryable<ToDoItem>>().Setup(x => x.Expression).Returns(dbData.Expression); dbSetMock.As<IQueryable<ToDoItem>>().Setup(x => x.ElementType).Returns(dbData.ElementType); dbSetMock.As<IQueryable<ToDoItem>>().Setup(x => x.GetEnumerator()).Returns(dbData.GetEnumerator()); var dbContextMock = new Mock<ApplicationDbContext>(); dbContextMock.Setup(x => x.Set<ToDoItem>()).Returns(dbSetMock.Object); var repo = new ToDoItemRepository(dbContextMock.Object); var result = repo.Update(newItem); Assert.AreEqual(newItem.Text, result.Text); Assert.AreEqual(newItem.DateCompletion, result.DateCompletion); Assert.AreEqual(newItem.Note, result.Note); Assert.AreEqual(newItem.IsCompleted, result.IsCompleted); Assert.AreSame(result.List, list); }
public ToDoItem UpdateToDoItem(int id, [FromBody] ToDoItem toDoItem) { toDoItem.Id = id; return(_toDoItemRepository.Update(toDoItem)); }
public ActionResult Sort() { string ids = Request.Form["ids"]; string[] sorted = ids.Split(','); List<long> l = new List<long>(); foreach (string id in sorted) { long temp = 0; if (long.TryParse(id.Replace("item",""),out temp)) { l.Add(temp); } } long accountId = MTApp.CurrentRequestContext.CurrentAdministrator(MTApp).Id; ToDoItemRepository repository = new ToDoItemRepository(MTApp.CurrentRequestContext); List<ToDoItem> items = repository.FindByAccountId(accountId); repository.AutoSubmit = false; int currentSort = 1; foreach (long itemid in l) { foreach (ToDoItem item in items) { if (item.Id == itemid ) { item.SortOrder = currentSort; currentSort += 1; repository.Update(item); } } } repository.SubmitChanges(); return new JsonResult() { Data = "result:true" }; }
public ActionResult Toggle(long id) { bool success = false; try { long accountId = MTApp.CurrentRequestContext.CurrentAdministrator(MTApp).Id; ToDoItemRepository repository = new ToDoItemRepository(MTApp.CurrentRequestContext); ToDoItem item = repository.Find(id); if (item != null) { if (item.AccountId == accountId) { item.IsComplete = !item.IsComplete; success = repository.Update(item); } } } catch { } return new RedirectResult("~/todo"); }
public void ToDoItemRepository_Update_ShouldReturnUpdatedEntity() { var list = new Order(); var itemToChange = new ToDoItem() { Id = 1, DateAdded = DateTime.MinValue, DateCompletion = default(DateTime), IsCompleted = false, IsFavourited = false, List = list, Note = "note", Text = "text" }; var dbData = new List <ToDoItem>() { itemToChange, new ToDoItem() { Id = 2, DateAdded = DateTime.MinValue, DateCompletion = default(DateTime), IsCompleted = false, IsFavourited = false, List = new Order(), Note = "note", Text = "text" }, new ToDoItem() { Id = 3, DateAdded = DateTime.MinValue, DateCompletion = default(DateTime), IsCompleted = false, IsFavourited = false, List = new Order(), Note = "note", Text = "text" } }.AsQueryable(); var newItem = new ToDoItem() { Id = 1, DateAdded = DateTime.MinValue, DateCompletion = default(DateTime), IsCompleted = false, IsFavourited = false, List = null, Note = "note1", Text = "text1" }; var dbSetMock = new Mock <DbSet <ToDoItem> >(); dbSetMock.As <IQueryable <ToDoItem> >().Setup(x => x.Provider).Returns(dbData.Provider); dbSetMock.As <IQueryable <ToDoItem> >().Setup(x => x.Expression).Returns(dbData.Expression); dbSetMock.As <IQueryable <ToDoItem> >().Setup(x => x.ElementType).Returns(dbData.ElementType); dbSetMock.As <IQueryable <ToDoItem> >().Setup(x => x.GetEnumerator()).Returns(dbData.GetEnumerator()); var dbContextMock = new Mock <ApplicationDbContext>(); dbContextMock.Setup(x => x.Set <ToDoItem>()).Returns(dbSetMock.Object); var repo = new ToDoItemRepository(dbContextMock.Object); var result = repo.Update(newItem); Assert.AreEqual(newItem.Text, result.Text); Assert.AreEqual(newItem.DateCompletion, result.DateCompletion); Assert.AreEqual(newItem.Note, result.Note); Assert.AreEqual(newItem.IsCompleted, result.IsCompleted); Assert.AreSame(result.List, list); }