コード例 #1
0
 public ActionResult Index(NewTaskViewModel newTask)
 {
     ViewBag.Message = "Please enter task details!";
     if (!ModelState.IsValid)
     {
         return View(newTask);
     }
     taskManager.CreateTask(newTask, User.Identity.Name);
     return View(newTask);
 }
コード例 #2
0
        /// <summary>
        /// Posts the specified new task.
        /// </summary>
        /// <param name="newTaskViewModel">The new task.</param>
        /// <param name="userName">Name of the user.</param>
        /// <returns>
        /// Created task.
        /// </returns>
        public Task CreateTask(NewTaskViewModel newTaskViewModel, string userName)
        {
            var task = new Task
            {
                UserName = userName,
                CreatedDate = DateTime.UtcNow,
                Description = newTaskViewModel.Description
            };

            if (null != newTaskViewModel.StartDate)
            {
                task.StartDate = newTaskViewModel.StartDate.Value.ToUniversalTime();
            }

            if (null != newTaskViewModel.EndDate)
            {
                task.EndDate = newTaskViewModel.EndDate.Value.ToUniversalTime();
            }

            taskMonitorContext.Tasks.Add(task);
            taskMonitorContext.SaveChanges();
            return task;
        }