Example #1
0
        public ActionResult Create(Task task)
        {
            if (ModelHelpers.Validate_Time(task.StartTime, task.EndTime))
            {
                ModelState.AddModelError("Error.", "The end time cannot be earlier than the start time.");
                return View();
            }
            if (ModelState.IsValid)
            {
                taskRepo.InsertTask(task, User.Identity.Name);
                taskRepo.Save();
                return RedirectToAction("Index");
            }

            return View(task);
        }
Example #2
0
 public void UpdateTask(Task Task)
 {
     //if the task doesn't exist, we will create it
     if (Task.ID == 0)
     {
         context.Tasks.Add(Task);
     }
     else
     {
         Task dbEntry = context.Tasks.Find(Task.ID);
         if (dbEntry != null)
         {
             dbEntry.StartTime = Task.StartTime;
             dbEntry.EndTime = Task.EndTime;
             dbEntry.Category = Task.Category;
             dbEntry.Description = Task.Description;
         }
     }
 }
Example #3
0
        public void Can_Delete()
        {
            Mock<ITaskRepository> mock = new Mock<ITaskRepository>();
            UserProfile testUser = new UserProfile { UserId = 1, UserName = "******" };
            var contextMock = new Mock<ControllerContext>();
            Task t2 = new Task { ID = 2, Description = "T2", UserProfile = testUser, UserID = 1 };
            mock.Setup(m => m.Tasks).Returns(new Task[] {
                new Task {ID = 1, Description = "T1", UserProfile = testUser, UserID = 1 },
                t2,
                new Task {ID = 3, Description = "T3", UserProfile = testUser, UserID = 1 }
                }.AsQueryable());
            contextMock.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("brad-greene");
            contextMock.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);
            TaskController target = new TaskController(mock.Object);
            target.ControllerContext = contextMock.Object;

            target.DeleteConfirmed(2);

            mock.Verify(m => m.DeleteTask(t2.ID));
        }
Example #4
0
        public void Can_Save_Changes()
        {
            Mock<ITaskRepository> mock = new Mock<ITaskRepository>();
            UserProfile testUser = new UserProfile { UserId = 1, UserName = "******" };
            var contextMock = new Mock<ControllerContext>();
            contextMock.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("brad-greene");
            contextMock.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);
            TaskController target = new TaskController(mock.Object);
            target.ControllerContext = contextMock.Object;

            Task t = new Task { Category = "misc" };
            ActionResult result = target.Edit(t);

            mock.Verify(m => m.UpdateTask(t));
        }
Example #5
0
 public void InsertTask(Task task, string userName)
 {
     task.UserProfile = context.UserProfiles.Where(u => u.UserName == userName).First();
      	        context.Tasks.Add(task);
 }
Example #6
0
 public ActionResult Edit(Task task)
 {
     if (ModelState.IsValid )
     {
         taskRepo.UpdateTask(task);
         taskRepo.Save();
         return RedirectToAction("Index");
     }
     return View(task);
 }