/// <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"); }
public static void AddTasksToDB() { // create some tasks with no associated date in order to try and see the 0 dates. var tasks = new List<Task>(); for (int i = 0; i < 5; i++) { var task = new Task(); var AssignedRoles = new List<Role>(); var role = new Role(); role.Name = "LineManager"; AssignedRoles.Add(role); task.AssignedRoles = AssignedRoles; var ColsolidatedAssignees = new List<SimpleUser>(); var user = new SimpleUser { EmailAddress = "*****@*****.**", UserId = "user_293ebdcf-d47c-4e63-9c12-3fbb6603b644", RelationshipName = "LineManager" }; ColsolidatedAssignees.Add(user); task.ConsolidatedAssignees = ColsolidatedAssignees; //task.ConsolidatedAssignees[0].UserId = "user_293ebdcf-d47c-4e63-9c12-3fbb6603b644"; //task.ConsolidatedAssignees[0].EmailAddress = "*****@*****.**"; task.ParentItemId = "sickness_d020fc7b-087d-43cb-93c4-8a89604958aa"; var createdBy = new SimpleUser { UserId = "user_293ebdcf-d47c-4e63-9c12-3fbb6603b644", EmailAddress = "*****@*****.**" }; task.CreatedBy = createdBy; //task.DueDate = DateTime.MinValue; //task.ConsolidatedCompletionDate = DateTime.MinValue; var assignedUser = new SimpleUser(); assignedUser.UserId = "user_293ebdcf-d47c-4e63-9c12-3fbb6603b644"; assignedUser.EmailAddress = "*****@*****.**"; assignedUser.FullName = "Andy Evans"; var assignedUsers = new List<SimpleUser> {assignedUser}; task.AssignedUsers = assignedUsers; task.DueDate = DateTime.Now.Date; task.ConsolidatedCompletionDate = DateTime.Now.Date; task.Id = i.ToString(); tasks.Add(task); } var store = new DocumentStore { ConnectionStringName = "RavenServer" }; store.Initialize(); using (var session = store.OpenSession()) { foreach (var task in tasks) { session.Store(task); task.UpdateAssignees(session); } session.SaveChanges(); } }
private Task GenerateATask(IUser user, Random rand) { var manager = user.Relationships.FirstOrDefault(r => r.RelationshipName == "LineManager"); if (manager == null) { return null; } var now = DateTime.UtcNow.Date; var dueDate = RandomDate(rand, now.AddDays(0 - 10), now); var commentNum = rand.Next(0, _config.TasksConfig.PossibleTitles.Count()); var task = new Task { AssignedUsers = new List<SimpleUser> {manager}, ConsolidatedAssignees = new List<SimpleUser> {manager}, CreatedBy = user.ToSimpleUser(), DueDate = dueDate, Id = IlluminateDatabase.GenerateId<Task>(), Title =FormatCommentFullName(_config.TasksConfig.PossibleTitles.ElementAt(commentNum),user) , Description = FormatCommentFullName(_config.TasksConfig.PossibleDescriptions.ElementAt(commentNum), user), ConsolidatedCompletionDate = now }; return task; }