Exemplo n.º 1
0
        /// <summary>
        /// Update the details of a task
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult Update(TaskViewModel model)
        {
            
            ModelState.Remove("CreatedBy");
            ModelState.Remove("AssignedToId");
            if (ModelState.IsValid)
            {
                using (var orgSession = OrgStore.OpenSession())
                {
                    
                    var task = orgSession.Load<Task>(model.Id);

                    task.DueDate = model.DueDate;
                    task.ConsolidatedCompletionDate = model.DueDate;
                    if (task.CompletedDate != null) task.CompletedDate = model.DueDate;


                    task.Title = model.Title;
                    task.Description = model.Description;

                    orgSession.Store(task);
                    orgSession.SaveChanges();

                    return JsonSuccess(task.ToTimelineItems(), "Task updated");
                }
            }
            return JsonError("Invalid data");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new Task
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public JsonResult Create(TaskViewModel model)
        {
            //remove Id from modelstate if tehre. 
            ModelState.Remove("Id"); 
            ModelState.Remove("CreatedBy");
            if (ModelState.IsValid)
            {
                using (var orgSession = OrgStore.OpenSession())
                {
                    //load the user that the task is for
                    var assignee = orgSession.Load<User>(model.AssignedToId);
                    var task = new Task
                               {
                                   CreatedBy = OrgUser.ToSimpleUser(),
                                   DueDate = model.DueDate.ToUniversalTime(),
                                   ConsolidatedCompletionDate = model.DueDate,
                                   AssignedUsers = new List<SimpleUser>{assignee.ToSimpleUser()},
                                   Title = model.Title,
                                   Description = model.Description,
                                   Id = IlluminateDatabase.GenerateId<Task>()
                               };

                    if (model.DueDate < DateTime.Now.Date)
                        task.ConsolidatedCompletionDate = DateTime.Now.Date;
                    orgSession.Store(task);
                    task.UpdateAssignees(orgSession);

                    orgSession.SaveChanges();

                    return JsonSuccess(task.ToTimelineItems(), "Task created");
                }
            }
            return JsonError("Invalid data");
        }