public ActionResult Details(Guid id) { ViewModels.Notes.NoteViewModel viewModel; Common.Models.Notes.Note model; Common.Models.Matters.Matter noteMatter; Common.Models.Tasks.Task noteTask; using (IDbConnection conn = Data.Database.Instance.GetConnection()) { model = Data.Notes.Note.Get(id, conn, false); viewModel = Mapper.Map <ViewModels.Notes.NoteViewModel>(model); noteMatter = Data.Notes.NoteMatter.GetRelatedMatter(id, conn, false); noteTask = Data.Notes.NoteTask.GetRelatedTask(id, conn, false); if (noteTask != null) { // Note belongs to a task noteMatter = Data.Tasks.Task.GetRelatedMatter(noteTask.Id.Value, conn, false); ViewBag.Task = noteTask; } viewModel.NoteNotifications = new List <ViewModels.Notes.NoteNotificationViewModel>(); Data.Notes.NoteNotification.ListForNote(id, conn, false).ForEach(x => { x.Contact = Data.Contacts.Contact.Get(x.Contact.Id.Value, conn, false); ViewModels.Notes.NoteNotificationViewModel vm = Mapper.Map <ViewModels.Notes.NoteNotificationViewModel>(x); vm.Contact = Mapper.Map <ViewModels.Contacts.ContactViewModel>(x.Contact); viewModel.NoteNotifications.Add(vm); }); PopulateCoreDetails(viewModel, conn); } ViewBag.Matter = noteMatter; return(View(viewModel)); }
public ActionResult Details(Guid id) { ViewModels.Notes.NoteViewModel viewModel; Common.Models.Notes.Note model; Common.Models.Matters.Matter noteMatter; Common.Models.Tasks.Task noteTask; model = Data.Notes.Note.Get(id); viewModel = Mapper.Map <ViewModels.Notes.NoteViewModel>(model); noteMatter = Data.Notes.NoteMatter.GetRelatedMatter(id); noteTask = Data.Notes.NoteTask.GetRelatedTask(id); if (noteTask != null) { // Note belongs to a task noteMatter = Data.Tasks.Task.GetRelatedMatter(noteTask.Id.Value); ViewData["TaskId"] = noteTask.Id.Value; ViewData["Task"] = noteTask.Title; } viewModel.NoteNotifications = new List <ViewModels.Notes.NoteNotificationViewModel>(); Data.Notes.NoteNotification.ListForNote(id).ForEach(x => { x.Contact = Data.Contacts.Contact.Get(x.Contact.Id.Value); ViewModels.Notes.NoteNotificationViewModel vm = Mapper.Map <ViewModels.Notes.NoteNotificationViewModel>(x); vm.Contact = Mapper.Map <ViewModels.Contacts.ContactViewModel>(x.Contact); viewModel.NoteNotifications.Add(vm); }); PopulateCoreDetails(viewModel); ViewData["MatterId"] = noteMatter.Id.Value; ViewData["Matter"] = noteMatter.Title; return(View(viewModel)); }
public ActionResult Index(ViewModels.Home.DashboardViewModel currentDVM) { int id; ViewModels.Home.DashboardViewModel viewModel; Common.Models.Contacts.Contact employee; Common.Models.Account.Users currentUser; List <Common.Models.Settings.TagFilter> tagFilter; Common.Models.Matters.Matter matter; List <ViewModels.Contacts.ContactViewModel> employeeContactList; employeeContactList = new List <ViewModels.Contacts.ContactViewModel>(); try { Data.Account.Users.List(); } catch (Exception) { return(RedirectToAction("Index", "Installation")); } if (RouteData.Values["Id"] != null) { id = int.Parse((string)RouteData.Values["Id"]); } else if (currentDVM.Employee != null && currentDVM.Employee.Id.HasValue) { id = currentDVM.Employee.Id.Value; } else { dynamic profile = ProfileBase.Create(Membership.GetUser().UserName); if (profile.ContactId != null && !string.IsNullOrEmpty(profile.ContactId)) { id = int.Parse(profile.ContactId); } else { throw new ArgumentNullException("Must supply an Id or have a ContactId set in profile."); } } employee = Data.Contacts.Contact.Get(id); currentUser = Data.Account.Users.Get(User.Identity.Name); viewModel = new ViewModels.Home.DashboardViewModel(); viewModel.Employee = Mapper.Map <ViewModels.Contacts.ContactViewModel>(employee); viewModel.MyTodoList = new List <Tuple <ViewModels.Matters.MatterViewModel, ViewModels.Tasks.TaskViewModel> >(); tagFilter = Data.Settings.UserTaskSettings.ListTagFiltersFor(currentUser); Data.Tasks.Task.GetTodoListFor(employee, tagFilter).ForEach(x => { matter = Data.Tasks.Task.GetRelatedMatter(x.Id.Value); viewModel.MyTodoList.Add( new Tuple <ViewModels.Matters.MatterViewModel, ViewModels.Tasks.TaskViewModel>( Mapper.Map <ViewModels.Matters.MatterViewModel>(matter), Mapper.Map <ViewModels.Tasks.TaskViewModel>(x))); }); viewModel.NotificationList = new List <ViewModels.Notes.NoteNotificationViewModel>(); Data.Notes.NoteNotification.ListAllNoteNotificationsForContact(employee.Id.Value).ForEach(x => { ViewModels.Notes.NoteNotificationViewModel nnvm = Mapper.Map <ViewModels.Notes.NoteNotificationViewModel>(x); nnvm.Note = Mapper.Map <ViewModels.Notes.NoteViewModel>(Data.Notes.Note.Get(x.Note.Id.Value)); viewModel.NotificationList.Add(nnvm); }); Data.Contacts.Contact.ListEmployeesOnly().ForEach(x => { employeeContactList.Add(Mapper.Map <ViewModels.Contacts.ContactViewModel>(x)); }); ViewData["EmployeeContactList"] = employeeContactList; return(View(viewModel)); }
public ActionResult Index(ViewModels.Home.DashboardViewModel currentDVM) { int id; ViewModels.Home.DashboardViewModel viewModel; Common.Models.Contacts.Contact employee; Common.Models.Account.Users currentUser; List <Common.Models.Settings.TagFilter> tagFilter; Common.Models.Matters.Matter matter; List <ViewModels.Contacts.ContactViewModel> employeeContactList; employeeContactList = new List <ViewModels.Contacts.ContactViewModel>(); using (IDbConnection conn = Data.Database.Instance.GetConnection()) { try { Data.Account.Users.List(conn, false); } catch (Exception) { return(RedirectToAction("Index", "Installation")); } if (RouteData.Values["Id"] != null) { id = int.Parse((string)RouteData.Values["Id"]); } else if (currentDVM.Employee != null && currentDVM.Employee.Id.HasValue) { id = currentDVM.Employee.Id.Value; } else { dynamic profile = ProfileBase.Create(Membership.GetUser().UserName); if (profile.ContactId != null && !string.IsNullOrEmpty(profile.ContactId)) { id = int.Parse(profile.ContactId); } else { id = -1; // Happens on initial setup } } if (id <= 0) { employee = null; viewModel = null; } else { employee = Data.Contacts.Contact.Get(id, conn, false); currentUser = Data.Account.Users.Get(User.Identity.Name, conn, false); viewModel = new ViewModels.Home.DashboardViewModel(); viewModel.Employee = Mapper.Map <ViewModels.Contacts.ContactViewModel>(employee); viewModel.MyTodoList = new List <Tuple <ViewModels.Matters.MatterViewModel, ViewModels.Tasks.TaskViewModel> >(); Data.Tasks.Task.GetTodoListFor(employee, null, null, conn, false).ForEach(x => { matter = Data.Tasks.Task.GetRelatedMatter(x.Id.Value, conn, false); viewModel.MyTodoList.Add( new Tuple <ViewModels.Matters.MatterViewModel, ViewModels.Tasks.TaskViewModel>( Mapper.Map <ViewModels.Matters.MatterViewModel>(matter), Mapper.Map <ViewModels.Tasks.TaskViewModel>(x))); }); viewModel.NotificationList = new List <ViewModels.Notes.NoteNotificationViewModel>(); Data.Notes.NoteNotification.ListAllNoteNotificationsForContact(employee.Id.Value, conn, false).ForEach(x => { ViewModels.Notes.NoteNotificationViewModel nnvm = Mapper.Map <ViewModels.Notes.NoteNotificationViewModel>(x); nnvm.Note = Mapper.Map <ViewModels.Notes.NoteViewModel>(Data.Notes.Note.Get(x.Note.Id.Value, conn, false)); viewModel.NotificationList.Add(nnvm); }); Data.Contacts.Contact.ListEmployeesOnly(conn, false).ForEach(x => { employeeContactList.Add(Mapper.Map <ViewModels.Contacts.ContactViewModel>(x)); }); viewModel.TasklessActiveMatters = new List <ViewModels.Matters.MatterViewModel>(); Data.Matters.Matter.ListMattersWithoutActiveTasks(5, conn, false).ForEach(x => { viewModel.TasklessActiveMatters.Add(Mapper.Map <ViewModels.Matters.MatterViewModel>(x)); }); viewModel.Activities = new List <Tuple <ViewModels.Activities.ActivityBaseViewModel, ViewModels.Activities.ActivityRegardingBaseViewModel> >(); Data.Activities.ActivityTask.GetGeneralActivities(employee.Id.Value, conn, false).ForEach(x => { Tuple <ViewModels.Activities.ActivityBaseViewModel, ViewModels.Activities.ActivityRegardingBaseViewModel> vm = null; ViewModels.Activities.ActivityBaseViewModel vm1; x.Type = Data.Activities.ActivityType.Get(x.Type.Id.Value, conn, false); vm1 = Mapper.Map <ViewModels.Activities.ActivityBaseViewModel>(x); vm1.Type = Mapper.Map <ViewModels.Activities.ActivityTypeViewModel>(x.Type); Common.Models.Activities.ActivityRegardingType regardingModel = Data.Activities.ActivityRegardingType.GetFromActivityId(x.Id.Value, conn, false); if (regardingModel.Title == "Lead") { Common.Models.Activities.ActivityRegardingLead lm = Data.Activities.ActivityRegardingLead.GetFromActivityId(x.Id.Value, conn, false); vm = new Tuple <ViewModels.Activities.ActivityBaseViewModel, ViewModels.Activities.ActivityRegardingBaseViewModel>(vm1, Mapper.Map <ViewModels.Activities.ActivityRegardingLeadViewModel>(lm)); } else if (regardingModel.Title == "Opportunity") { Common.Models.Activities.ActivityRegardingOpportunity om = Data.Activities.ActivityRegardingOpportunity.GetFromActivityId(x.Id.Value, conn, false); vm = new Tuple <ViewModels.Activities.ActivityBaseViewModel, ViewModels.Activities.ActivityRegardingBaseViewModel>(vm1, Mapper.Map <ViewModels.Activities.ActivityRegardingOpportunityViewModel>(om)); } viewModel.Activities.Add(vm); }); Random rnd = new Random(); int activeMatters = Data.Matters.Matter.CountAllActiveMatters(conn, false); int activeMattersWithoutTasks = Data.Matters.Matter.CountAllMattersWithoutActiveTasks(conn, false); ViewBag.MattersWithActiveTasks = activeMatters - activeMattersWithoutTasks; ViewBag.MattersWithoutActiveTasks = activeMattersWithoutTasks; } } ViewBag.EmployeeContactList = employeeContactList; return(View(viewModel)); }