// // GET: /ToDo/ public ActionResult Index() { bool failed = false; if (Request.QueryString["failed"] != null) { failed = true; } List<ToDoItem> items = new List<ToDoItem>(); UserAccount adminUser = MTApp.CurrentRequestContext.CurrentAdministrator(MTApp); if (adminUser != null) { ToDoItemRepository repository = new ToDoItemRepository(MTApp.CurrentRequestContext); items = repository.FindByAccountId(adminUser.Id); } FlashFailure("Failed to Create Task. Please Try Again."); return View(items); }
public ActionResult Create(string title, string details) { bool fail = false; try { ToDoItem item = new ToDoItem() { AccountId = MTApp.CurrentRequestContext.CurrentAdministrator(MTApp).Id, Details = details, IsComplete = false, Title = title }; ToDoItemRepository repository = new ToDoItemRepository(MTApp.CurrentRequestContext); if (repository.Create(item)) { fail = false; } else { fail = true; } } catch (Exception ex) { fail = true; } string destination = "~/todo"; if (fail) { destination += "?failed=1"; } return new RedirectResult(destination); }
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 ActionResult Delete(long id, FormCollection collection) { 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) { success = repository.Delete(id); } } } catch { } return new JsonResult() { Data = MerchantTribe.Web.Json.ObjectToJson(new { result = success }) }; }
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 Setup() { _repository = new Repository <ToDoItem>(DBContext); _toDoItemRepository = new ToDoItemRepository(_repository, Mapper); }
public HomeController(ToDoItemRepository toDoItemRepository) { _toDoItemRepository = toDoItemRepository; }