public static Common.Models.Events.EventTask RelateToTask(Common.Models.Events.Event model, Common.Models.Tasks.Task task, Common.Models.Account.Users actor) { Common.Models.Events.EventTask et; DBOs.Events.EventTask dbo = null; et = Data.Events.EventTask.Get(task.Id.Value, model.Id.Value); if (et != null) { return(et); } et = new Common.Models.Events.EventTask(); et.Id = Guid.NewGuid(); et.CreatedBy = et.ModifiedBy = actor; et.Created = et.Modified = DateTime.UtcNow; et.Event = model; et.Task = task; dbo = Mapper.Map <DBOs.Events.EventTask>(et); using (IDbConnection conn = Database.Instance.GetConnection()) { conn.Execute("INSERT INTO \"event_task\" (\"id\", \"event_id\", \"task_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " + "VALUES (@Id, @EventId, @TaskId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)", dbo); } return(et); }
public ActionResult Create() { List <ViewModels.Contacts.ContactViewModel> employeeContactList; Common.Models.Matters.Matter matter = null; Common.Models.Tasks.Task task = null; employeeContactList = new List <ViewModels.Contacts.ContactViewModel>(); if (Request["MatterId"] != null) { matter = Data.Matters.Matter.Get(Guid.Parse(Request["MatterId"])); } else if (Request["TaskId"] != null) { task = Data.Tasks.Task.Get(long.Parse(Request["TaskId"])); matter = Data.Tasks.Task.GetRelatedMatter(task.Id.Value); ViewData["TaskId"] = task.Id.Value; ViewData["Task"] = task.Title; } Data.Contacts.Contact.ListEmployeesOnly().ForEach(x => { employeeContactList.Add(Mapper.Map <ViewModels.Contacts.ContactViewModel>(x)); }); ViewData["MatterId"] = matter.Id.Value; ViewData["Matter"] = matter.Title; ViewData["EmployeeContactList"] = employeeContactList; return(View(new ViewModels.Notes.NoteViewModel() { Timestamp = DateTime.Now })); }
public static Common.Models.Tasks.Task Edit( Transaction t, Common.Models.Tasks.Task model, Common.Models.Account.Users modifier) { return(Edit(model, modifier, t.Connection, false)); }
public static Common.Models.Tasks.TaskMatter RelateMatter(Common.Models.Tasks.Task taskModel, Guid matterId, Common.Models.Account.Users creator) { Common.Models.Tasks.TaskMatter taskMatter = new Common.Models.Tasks.TaskMatter() { Id = Guid.NewGuid(), Matter = new Common.Models.Matters.Matter() { Id = matterId }, Task = taskModel, Created = DateTime.UtcNow, Modified = DateTime.UtcNow, CreatedBy = creator, ModifiedBy = creator }; DBOs.Tasks.TaskMatter dbo = Mapper.Map <DBOs.Tasks.TaskMatter>(taskMatter); using (IDbConnection conn = Database.Instance.GetConnection()) { conn.Execute("INSERT INTO \"task_matter\" (\"id\", \"task_id\", \"matter_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " + "VALUES (@Id, @TaskId, @MatterId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)", dbo); } return(taskMatter); }
public static Common.Models.Tasks.Task Create( Transaction t, Common.Models.Tasks.Task model, Common.Models.Account.Users creator) { return(Create(model, creator, t.Connection, false)); }
public static Common.Models.Tasks.Task Create( Common.Models.Tasks.Task model, Common.Models.Account.Users creator, IDbConnection conn = null, bool closeConnection = true) { model.CreatedBy = model.ModifiedBy = creator; model.Created = model.Modified = DateTime.UtcNow; DBOs.Tasks.Task dbo = Mapper.Map <DBOs.Tasks.Task>(model); conn = DataHelper.OpenIfNeeded(conn); if (conn.Execute("INSERT INTO \"task\" (\"title\", \"description\", \"projected_start\", \"due_date\", \"projected_end\", " + "\"actual_end\", \"parent_id\", \"is_grouping_task\", \"sequential_predecessor_id\", \"active\", \"utc_created\", " + "\"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " + "VALUES (@Title, @Description, @ProjectedStart, @DueDate, @ProjectedEnd, @ActualEnd, @ParentId, @IsGroupingTask, " + "@SequentialPredecessorId, @Active, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)", dbo) > 0) { model.Id = conn.Query <DBOs.Tasks.Task>("SELECT currval(pg_get_serial_sequence('task', 'id')) AS \"id\"").Single().Id; } DataHelper.Close(conn, closeConnection); return(model); }
public static Common.Models.Tasks.TaskMatter RelateMatter( Transaction t, Common.Models.Tasks.Task taskModel, Guid matterId, Common.Models.Account.Users creator) { return(RelateMatter(taskModel, matterId, creator, t.Connection, false)); }
public ActionResult Create(long id) { Common.Models.Matters.Matter matter; Common.Models.Tasks.Task model = Data.Tasks.Task.Get(id); matter = Data.Tasks.Task.GetRelatedMatter(model.Id.Value); ViewData["Task"] = model.Title; ViewData["TaskId"] = model.Id; ViewData["Matter"] = matter.Title; ViewData["MatterId"] = matter.Id; return(View(new ViewModels.Tasks.TaskTagViewModel() { Task = Mapper.Map <ViewModels.Tasks.TaskViewModel>(model) })); }
public static Common.Models.Events.EventTask RelateToTask(Common.Models.Events.Event model, Common.Models.Tasks.Task task, Common.Models.Account.Users actor, IDbConnection conn = null, bool closeConnection = true) { Common.Models.Events.EventTask et; DBOs.Events.EventTask dbo = null; et = Data.Events.EventTask.Get(task.Id.Value, model.Id.Value); if (et != null) { return(et); } et = new Common.Models.Events.EventTask(); et.Id = Guid.NewGuid(); et.CreatedBy = et.ModifiedBy = actor; et.Created = et.Modified = DateTime.UtcNow; et.Event = model; et.Task = task; dbo = Mapper.Map <DBOs.Events.EventTask>(et); conn = DataHelper.OpenIfNeeded(conn); if (conn.Execute("INSERT INTO \"event_task\" (\"id\", \"event_id\", \"task_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " + "VALUES (@Id, @EventId, @TaskId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)", dbo) > 0) { model.Id = conn.Query <DBOs.Events.EventTask>("SELECT currval(pg_get_serial_sequence('event_task', 'id')) AS \"id\"").Single().Id; } DataHelper.Close(conn, closeConnection); return(et); }
public ActionResult Create() { List <ViewModels.Contacts.ContactViewModel> employeeContactList; Common.Models.Matters.Matter matter = null; Common.Models.Tasks.Task task = null; employeeContactList = new List <ViewModels.Contacts.ContactViewModel>(); using (IDbConnection conn = Data.Database.Instance.GetConnection()) { if (Request["MatterId"] != null) { matter = Data.Matters.Matter.Get(Guid.Parse(Request["MatterId"]), conn, false); } else if (Request["TaskId"] != null) { task = Data.Tasks.Task.Get(long.Parse(Request["TaskId"]), conn, false); matter = Data.Tasks.Task.GetRelatedMatter(task.Id.Value, conn, false); ViewBag.Task = task; } Data.Contacts.Contact.ListEmployeesOnly(conn, false).ForEach(x => { employeeContactList.Add(Mapper.Map <ViewModels.Contacts.ContactViewModel>(x)); }); } ViewBag.Matter = matter; ViewBag.EmployeeContactList = employeeContactList; return(View(new ViewModels.Notes.NoteViewModel() { Timestamp = DateTime.Now })); }
public static Common.Models.Tasks.TaskMatter RelateMatter( Common.Models.Tasks.Task taskModel, Guid matterId, Common.Models.Account.Users creator, IDbConnection conn = null, bool closeConnection = true) { Common.Models.Tasks.TaskMatter taskMatter = new Common.Models.Tasks.TaskMatter() { Id = Guid.NewGuid(), Matter = new Common.Models.Matters.Matter() { Id = matterId }, Task = taskModel, Created = DateTime.UtcNow, Modified = DateTime.UtcNow, CreatedBy = creator, ModifiedBy = creator }; DBOs.Tasks.TaskMatter dbo = Mapper.Map <DBOs.Tasks.TaskMatter>(taskMatter); conn = DataHelper.OpenIfNeeded(conn); if (conn.Execute("INSERT INTO \"task_matter\" (\"id\", \"task_id\", \"matter_id\", \"utc_created\", \"utc_modified\", \"created_by_user_pid\", \"modified_by_user_pid\") " + "VALUES (@Id, @TaskId, @MatterId, @UtcCreated, @UtcModified, @CreatedByUserPId, @ModifiedByUserPId)", dbo) > 0) { taskMatter.Id = conn.Query <DBOs.Tasks.TaskMatter>("SELECT currval(pg_get_serial_sequence('task_matter', 'id')) AS \"id\"").Single().Id; } DataHelper.Close(conn, closeConnection); return(taskMatter); }
public ActionResult PhoneCall(Guid id, ViewModels.Tasks.PhoneCallViewModel viewModel) { int contactId; Common.Models.Account.Users currentUser; Common.Models.Matters.Matter matter; dynamic profile = ProfileBase.Create(Membership.GetUser().UserName); if (profile.ContactId == null && string.IsNullOrEmpty(profile.ContactId)) { throw new Exception("Profile.ContactId not configured."); } using (Data.Transaction trans = Data.Transaction.Create(true)) { try { contactId = int.Parse(profile.ContactId); currentUser = Data.Account.Users.Get(trans, User.Identity.Name); matter = Data.Matters.Matter.Get(trans, id); // Task Common.Models.Tasks.Task task = new Common.Models.Tasks.Task() { Active = true, DueDate = DateTime.Now, Title = viewModel.Title, Description = new Ganss.XSS.HtmlSanitizer().Sanitize(viewModel.TaskAndNoteDetails) }; // TaskAssignedContact Common.Models.Tasks.TaskAssignedContact taskAssignedContact = new Common.Models.Tasks.TaskAssignedContact() { Contact = new Common.Models.Contacts.Contact() { Id = contactId }, Task = task, AssignmentType = Common.Models.Tasks.AssignmentType.Direct }; // Time Common.Models.Timing.Time time = new Common.Models.Timing.Time() { Billable = viewModel.Billable, Details = viewModel.TimeDetails, Start = viewModel.Start, Stop = viewModel.Stop, TimeCategory = new Common.Models.Timing.TimeCategory() { Id = viewModel.TimeCategory.Id.Value }, Worker = new Common.Models.Contacts.Contact() { Id = contactId } }; // Note Common.Models.Notes.Note note = new Common.Models.Notes.Note() { Body = viewModel.TaskAndNoteDetails, Timestamp = DateTime.Now, Title = viewModel.Title }; task = Data.Tasks.Task.Create(trans, task, currentUser); Data.Tasks.Task.RelateMatter(trans, task, matter.Id.Value, currentUser); Data.Tasks.TaskAssignedContact.Create(trans, taskAssignedContact, currentUser); if (viewModel.MakeTime) { time = Data.Timing.Time.Create(trans, time, currentUser); Data.Timing.Time.RelateTask(trans, time, task.Id.Value, currentUser); } if (viewModel.MakeNote) { note = Data.Notes.Note.Create(trans, note, currentUser); Data.Notes.Note.RelateTask(trans, note, task.Id.Value, currentUser); if (viewModel.NotifyContactIds != null) { foreach (string x in viewModel.NotifyContactIds) { Data.Notes.NoteNotification.Create(trans, new Common.Models.Notes.NoteNotification() { Contact = new Common.Models.Contacts.Contact() { Id = int.Parse(x) }, Note = note, Cleared = null }, currentUser); } ; } } trans.Commit(); return(RedirectToAction("Details", "Tasks", new { Id = task.Id })); } catch { trans.Rollback(); return(PhoneCall(id)); } } }
public ActionResult PhoneCall(Guid id, ViewModels.Tasks.PhoneCallViewModel viewModel) { int contactId; Common.Models.Account.Users currentUser; Common.Models.Matters.Matter matter; dynamic profile = ProfileBase.Create(Membership.GetUser().UserName); if (profile.ContactId == null && string.IsNullOrEmpty(profile.ContactId)) throw new Exception("Profile.ContactId not configured."); using (Data.Transaction trans = Data.Transaction.Create(true)) { try { contactId = int.Parse(profile.ContactId); currentUser = Data.Account.Users.Get(trans, User.Identity.Name); matter = Data.Matters.Matter.Get(trans, id); // Task Common.Models.Tasks.Task task = new Common.Models.Tasks.Task() { Active = true, DueDate = DateTime.Now, Title = viewModel.Title, Description = new Ganss.XSS.HtmlSanitizer().Sanitize(viewModel.TaskAndNoteDetails) }; // TaskAssignedContact Common.Models.Tasks.TaskAssignedContact taskAssignedContact = new Common.Models.Tasks.TaskAssignedContact() { Contact = new Common.Models.Contacts.Contact() { Id = contactId }, Task = task, AssignmentType = Common.Models.Tasks.AssignmentType.Direct }; // Time Common.Models.Timing.Time time = new Common.Models.Timing.Time() { Billable = viewModel.Billable, Details = viewModel.TimeDetails, Start = viewModel.Start, Stop = viewModel.Stop, Worker = new Common.Models.Contacts.Contact() { Id = contactId } }; // Note Common.Models.Notes.Note note = new Common.Models.Notes.Note() { Body = viewModel.TaskAndNoteDetails, Timestamp = DateTime.Now, Title = viewModel.Title }; task = Data.Tasks.Task.Create(trans, task, currentUser); Data.Tasks.Task.RelateMatter(trans, task, matter.Id.Value, currentUser); Data.Tasks.TaskAssignedContact.Create(trans, taskAssignedContact, currentUser); if (viewModel.MakeTime) { time = Data.Timing.Time.Create(trans, time, currentUser); Data.Timing.Time.RelateTask(trans, time, task.Id.Value, currentUser); } if (viewModel.MakeNote) { note = Data.Notes.Note.Create(trans, note, currentUser); Data.Notes.Note.RelateTask(trans, note, task.Id.Value, currentUser); if (viewModel.NotifyContactIds != null) { foreach (string x in viewModel.NotifyContactIds) { Data.Notes.NoteNotification.Create(trans, new Common.Models.Notes.NoteNotification() { Contact = new Common.Models.Contacts.Contact() { Id = int.Parse(x) }, Note = note, Cleared = null }, currentUser); }; } } trans.Commit(); return RedirectToAction("Details", "Tasks", new { Id = task.Id }); } catch { trans.Rollback(); return PhoneCall(id); } } }
private static void UpdateGroupingTaskProperties(Common.Models.Tasks.Task groupingTask) { bool groupingTaskChanged = false; using (IDbConnection conn = Database.Instance.GetConnection()) { // Projected Start DBOs.Tasks.Task temp = conn.Query <DBOs.Tasks.Task>( "SELECT * FROM \"task\" WHERE \"parent_id\"=@ParentId AND \"utc_disabled\" is null ORDER BY \"projected_start\" DESC limit 1", new { ParentId = groupingTask.Id.Value }).SingleOrDefault(); // If temp.ProjectedStart has a value then we know that there are no rows // with null value and so, we may update the grouping task to be the // earliest projected start value. However, if null, then we need to // set the grouping task's projected start value to null. if (temp.ProjectedStart.HasValue) { temp = conn.Query <DBOs.Tasks.Task>( "SELECT * FROM \"task\" WHERE \"parent_id\"=@ParentId AND \"utc_disabled\" is null ORDER BY \"projected_start\" ASC limit 1", new { ParentId = groupingTask.Id.Value }).SingleOrDefault(); if (groupingTask.ProjectedStart != temp.ProjectedStart) { groupingTask.ProjectedStart = temp.ProjectedStart; groupingTaskChanged = true; } } else { if (groupingTask.ProjectedStart.HasValue) { groupingTask.ProjectedStart = null; groupingTaskChanged = true; } } // Due Date temp = conn.Query <DBOs.Tasks.Task>( "SELECT * FROM \"task\" WHERE \"parent_id\"=@ParentId AND \"utc_disabled\" is null ORDER BY \"due_date\" DESC limit 1", new { ParentId = groupingTask.Id.Value }).SingleOrDefault(); if (temp.DueDate != groupingTask.DueDate) { groupingTask.DueDate = temp.DueDate; groupingTaskChanged = true; } // Projected End temp = conn.Query <DBOs.Tasks.Task>( "SELECT * FROM \"task\" WHERE \"parent_id\"=@ParentId AND \"utc_disabled\" is null ORDER BY \"projected_end\" DESC limit 1", new { ParentId = groupingTask.Id.Value }).SingleOrDefault(); if (temp.ProjectedEnd != groupingTask.ProjectedEnd) { groupingTask.ProjectedEnd = temp.ProjectedEnd; groupingTaskChanged = true; } // Actual End temp = conn.Query <DBOs.Tasks.Task>( "SELECT * FROM \"task\" WHERE \"parent_id\"=@ParentId AND \"utc_disabled\" is null ORDER BY \"actual_end\" DESC limit 1", new { ParentId = groupingTask.Id.Value }).SingleOrDefault(); if (temp.ActualEnd != groupingTask.ActualEnd) { groupingTask.ActualEnd = temp.ActualEnd; groupingTaskChanged = true; } // Update grouping task if needed if (groupingTaskChanged) { DBOs.Tasks.Task task = Mapper.Map <DBOs.Tasks.Task>(groupingTask); conn.Execute("UPDATE \"task\" SET \"projected_start\"=@ProjectedStart, \"due_date\"=@DueDate, \"projected_end\"=@ProjectedEnd, " + "\"actual_end\"=@ActualEnd WHERE \"id\"=@Id", task); if (groupingTask.Parent != null && groupingTask.Parent.Id.HasValue) { UpdateGroupingTaskProperties(OpenLawOffice.Data.Tasks.Task.Get(groupingTask.Parent.Id.Value)); } } } }
public static Common.Models.Tasks.Task Edit(Common.Models.Tasks.Task model, Common.Models.Account.Users modifier) { /* * We need to consider how to handle the relationship modifications * * First, basic assumptions: * 1) If a task has a sequential predecessor then it cannot independently specify its parent * * * Parent - if the parent is modified * * Sequential Predecessor * 1) If changed, need to cascade changes to all subsequent sequence members * 2) If removed from sequence, need to defer to user's parent selection * 3) If added to sequence, need to override user's parent selection * * * UI should be like: * * If sequence member: * [Remove from Sequence] * * * If NOT sequence member: * This task is not currently part of a task sequence. If you would like to make this * task part of a task sequence, click here. * -- OnClick --> * Please select the task you wish t * */ if (model.Parent != null && model.Parent.Id.HasValue) { // There is a proposed parent, we need to check and make sure it is not trying // to set itself as its parent if (model.Parent.Id.Value == model.Id) { throw new ArgumentException("Task cannot have itself as its parent."); } } model.ModifiedBy = modifier; model.Modified = DateTime.UtcNow; DBOs.Tasks.Task dbo = Mapper.Map <DBOs.Tasks.Task>(model); using (IDbConnection conn = Database.Instance.GetConnection()) { conn.Execute("UPDATE \"task\" SET " + "\"title\"=@Title, \"description\"=@Description, \"projected_start\"=@ProjectedStart, " + "\"due_date\"=@DueDate, \"projected_end\"=@ProjectedEnd, \"actual_end\"=@ActualEnd, \"parent_id\"=@ParentId, " + "\"active\"=@Active, \"utc_modified\"=@UtcModified, \"modified_by_user_pid\"=@ModifiedByUserPId " + "WHERE \"id\"=@Id", dbo); } if (model.Parent != null && model.Parent.Id.HasValue) { UpdateGroupingTaskProperties(OpenLawOffice.Data.Tasks.Task.Get(model.Parent.Id.Value)); } return(model); }