public IActionResult AddKWTask(KWTaskVM vm, int?staffProfileID, string returnURL) { var kwtask = new KWTask { Message = vm.NewKWTask.Message, AlertDate = vm.NewKWTask.AlertDate, DateCreated = vm.NewKWTask.DateCreated, DateDue = vm.NewKWTask.DateDue, Priority = vm.NewKWTask.Priority }; if (kwtask.AlertDate == null) { kwtask.Type = "Task"; } else { kwtask.Type = "Alert"; } if (staffProfileID != null) { StaffProfile staff = staffRepo.GetStaffProfileByID((int)staffProfileID); staff.Tasks.Add(kwtask); } taskRepo.AddKWTask(kwtask); //TODO: See if there is a way to just close the modal and not refresh the page return(Redirect(returnURL)); }
public ActionResult Edit(KWTaskVM vm, int KWTaskID) { KWTask kwtask = taskRepo.GetKWTaskByID(KWTaskID); kwtask.Message = vm.NewKWTask.Message; kwtask.AlertDate = vm.NewKWTask.AlertDate; kwtask.DateDue = vm.NewKWTask.DateDue; kwtask.Priority = vm.NewKWTask.Priority; kwtask.Type = vm.NewKWTask.Type; if (kwtask.AlertDate == null) { kwtask.Type = "Task"; } else { kwtask.Type = "Alert"; } int verify = taskRepo.UpdateKWTask(kwtask); if (verify == 1) { return(RedirectToAction("AllKWTasks")); } else { ModelState.AddModelError("", "Task Not Found"); } return(RedirectToAction("AllKWTasks")); }
public StaffProfile GetProfileByTask(KWTask task) { foreach (var p in context.StaffProfiles) { if (p.Tasks.Contains(task)) { return(p); } } return(null); }
public Interaction GetAssociatedInteraction(KWTask task) { foreach (Interaction i in context.Interactions) { if (i.TaskForeignKey == task.KWTaskID) { return(i); } } return(null); }
private bool ProcessAssign(KWTask t, List <StaffProfile> sps, bool clear) { foreach (StaffProfile sp in sps) { if (sp.Tasks.Contains(t)) { sp.Tasks.Remove(t); staffRepo.UpdateStaff(sp); } } return(true); }
//First unassigns the task from staff, then assigns it, then updates the repo private bool ProcessAssign(KWTask t, List <StaffProfile> sps, StaffProfile staff) { foreach (StaffProfile sp in sps) { if (sp.Tasks.Contains(t)) { sp.Tasks.Remove(t); } } staff.Tasks.Add(t); int verify = staffRepo.UpdateStaff(staff); if (verify > 0) { return(true); } else { return(false); } }
public IActionResult Delete(int id) { KWTask kwtask = taskRepo.GetKWTaskByID(id); if (kwtask != null) { var interaction = taskRepo.GetAssociatedInteraction(kwtask); if (interaction != null) { interaction.Task = null; interaction.TaskForeignKey = null; intRepo.UpdateInteraction(interaction); } taskRepo.DeleteKWTask(kwtask); return(RedirectToAction("AllKWTasks")); } else { ModelState.AddModelError("", "Task Not Found"); } return(RedirectToAction("AllKWTasks")); }
public ActionResult Edit(InteractionVM iVM, string taskAction = "") { var i = iVM.NewInteraction; if (i != null) { Interaction interaction = intRepo.GetInteractionById(i.InteractionID); if (iVM.Field == "Notes") { interaction.Notes = i.Notes; } else if (iVM.Field == "NextStep") { if (iVM.Task != null && taskAction == "New") { KWTask task = new KWTask() { AlertDate = iVM.Task.AlertDate, DateDue = iVM.Task.DateDue, Message = iVM.Task.Message, Priority = iVM.Task.Priority, DateCreated = iVM.Task.DateCreated }; if (task.AlertDate == null) { task.Type = "Task"; } else { task.Type = "Alert"; } var profile = staffRepo.GetStaffProfileByFullName(Helper.StaffProfileLoggedIn.FirstName, Helper.StaffProfileLoggedIn.LastName); profile.Tasks.Add(task); taskRepo.AddKWTask(task); interaction.Task = task; task.Interaction = interaction; taskRepo.UpdateKWTask(task); } else if (iVM.Task != null && taskAction == "Edit") { KWTask task = taskRepo.GetKWTaskByID(iVM.Task.KWTaskID); task.Message = iVM.Task.Message; task.AlertDate = iVM.Task.AlertDate; task.DateDue = iVM.Task.DateDue; task.Priority = iVM.Task.Priority; taskRepo.UpdateKWTask(task); } else { interaction.NextStep = i.NextStep; } } else if (iVM.Field == "Date Created") { interaction.DateCreated = i.DateCreated; } int verify = intRepo.UpdateInteraction(interaction); //Repository and broker.Interactions reflect proper values here if (verify == 1) { //TODO add feedback of success return(RedirectToAction("BrokerInteractions", new { BrokerID = iVM.BrokerID })); } else { //TODO add feedback for error } } else { ModelState.AddModelError("", "Interaction Not Found"); } return(RedirectToAction("BrokerInteractions", new { BrokerID = iVM.BrokerID })); }
public int UpdateKWTask(KWTask kwtask) { context.KWTasks.Update(kwtask); return(context.SaveChanges()); }
public int DeleteKWTask(KWTask kwtask) { context.KWTasks.Remove(kwtask); return(context.SaveChanges()); }
public int AddKWTask(KWTask kwtask) { context.KWTasks.Add(kwtask); return(context.SaveChanges()); }
public static async void EnsurePopulated(IApplicationBuilder app) { ApplicationDbContext context = app.ApplicationServices.GetRequiredService <ApplicationDbContext>(); UserManager <StaffUser> userManager = app.ApplicationServices.GetRequiredService <UserManager <StaffUser> >(); RoleManager <IdentityRole> roleManager = app.ApplicationServices.GetRequiredService <RoleManager <IdentityRole> >(); string firstName = "Bob"; string lastName = "Loblaw"; string email = "*****@*****.**"; bool notify = true; string role = "Staff"; string password = "******"; //Create Identity User before StaffProfile, so you can add to the profile //Populates staff members if (!context.StaffProfiles.Any()) { StaffUser user = await userManager.FindByEmailAsync(email); if (user == null) { user = new StaffUser { UserName = email }; IdentityResult result = await userManager.CreateAsync(user, password); if (await roleManager.FindByNameAsync(role) == null) { await roleManager.CreateAsync(new IdentityRole("Staff")); if (result.Succeeded) { await userManager.AddToRoleAsync(user, role); } } } StaffProfile profile = new StaffProfile { FirstName = firstName, LastName = lastName, Email = email, EmailNotifications = notify, User = user, Role = role }; context.StaffProfiles.Add(profile); firstName = "Nicole"; lastName = "Wedertz"; email = "*****@*****.**"; notify = true; role = "Staff"; password = "******"; //Create Identity User before StaffProfile, so you can add to the profile //Populates staff members user = await userManager.FindByEmailAsync(email); if (user == null) { user = new StaffUser { UserName = email }; IdentityResult result = await userManager.CreateAsync(user, password); if (await roleManager.FindByNameAsync(role) == null) { await roleManager.CreateAsync(new IdentityRole("Staff")); if (result.Succeeded) { await userManager.AddToRoleAsync(user, role); } } } profile = new StaffProfile { FirstName = firstName, LastName = lastName, Email = email, EmailNotifications = notify, User = user, Role = role }; context.StaffProfiles.Add(profile); firstName = "Tom"; lastName = "Dye"; email = "*****@*****.**"; notify = true; role = "Staff"; password = "******"; //Create Identity User before StaffProfile, so you can add to the profile //Populates staff members user = await userManager.FindByEmailAsync(email); if (user == null) { user = new StaffUser { UserName = email }; IdentityResult result = await userManager.CreateAsync(user, password); if (await roleManager.FindByNameAsync(role) == null) { await roleManager.CreateAsync(new IdentityRole("Staff")); if (result.Succeeded) { await userManager.AddToRoleAsync(user, role); } } } profile = new StaffProfile { FirstName = firstName, LastName = lastName, Email = email, EmailNotifications = notify, User = user, Role = role }; context.StaffProfiles.Add(profile); // Second identity + person, to test Authorization firstName = "Liz"; lastName = "Lemon"; email = "*****@*****.**"; notify = true; role = "Admin"; password = "******"; user = await userManager.FindByEmailAsync(email); if (user == null) { user = new StaffUser { UserName = email }; IdentityResult result = await userManager.CreateAsync(user, password); if (await roleManager.FindByNameAsync(role) == null) { await roleManager.CreateAsync(new IdentityRole("Admin")); if (result.Succeeded) { await userManager.AddToRoleAsync(user, role); } } } profile = new StaffProfile { FirstName = firstName, LastName = lastName, Email = email, EmailNotifications = notify, User = user, Role = role }; context.StaffProfiles.Add(profile); // Second identity + person, to test Authorization firstName = "Ad"; lastName = "Min"; email = "*****@*****.**"; notify = false; role = "Admin"; password = "******"; user = await userManager.FindByEmailAsync(email); if (user == null) { user = new StaffUser { UserName = email }; IdentityResult result = await userManager.CreateAsync(user, password); if (await roleManager.FindByNameAsync(role) == null) { await roleManager.CreateAsync(new IdentityRole("Admin")); if (result.Succeeded) { await userManager.AddToRoleAsync(user, role); } } } profile = new StaffProfile { FirstName = firstName, LastName = lastName, Email = email, EmailNotifications = notify, User = user, Role = role }; context.StaffProfiles.Add(profile); context.SaveChanges(); } //Populates Brokers if (!context.Brokers.Any()) { //Not specifying a status should default to active Broker broker = new Broker { FirstName = "Lonny", LastName = "Jenkins", Email = "*****@*****.**", EmailNotifications = true, Type = "New Broker" }; context.Brokers.Add(broker); //Not specifying a status shoudl default to active broker = new Broker { FirstName = "Samantha", LastName = "Coldwater", Email = "*****@*****.**", EmailNotifications = true, Type = "In Transition" }; context.Brokers.Add(broker); broker = new Broker { FirstName = "Brooke", LastName = "Schelling", Email = "*****@*****.**", EmailNotifications = true, Type = "New Broker", Status = "Inactive" }; context.Brokers.Add(broker); broker = new Broker { FirstName = "Jack", LastName = "Johnson", Email = "*****@*****.**", EmailNotifications = false, Type = "In Transition", }; context.Brokers.Add(broker); broker = new Broker { FirstName = "Janet", LastName = "Schwimmer", Email = "*****@*****.**", EmailNotifications = true, Type = "In Transition", }; context.Brokers.Add(broker); broker = new Broker { FirstName = "Wyatt", LastName = "Earp", Email = "*****@*****.**", EmailNotifications = false, Type = "In Transition", }; context.Brokers.Add(broker); broker = new Broker { FirstName = "Richard", LastName = "Kimble", Email = "*****@*****.**", EmailNotifications = false, Type = "New Broker", }; context.Brokers.Add(broker); broker = new Broker { FirstName = "Ty", LastName = "Burrell", Email = "*****@*****.**", EmailNotifications = true, Type = "New Broker", }; context.Brokers.Add(broker); context.SaveChanges(); } //Populate Messages if (!context.Messages.Any()) { StaffProfile profile = context.StaffProfiles.First(); Message message = new Message { Subject = "Staff Meeting", Body = "Don't forget we have a morning meeting tomorrow", From = "*****@*****.**", DateSent = DateTime.Now }; Message message2 = new Message { Subject = "Broker Meeting", Body = "All Brokers please make sure you meet us at the office tomorrow", From = "*****@*****.**", DateSent = DateTime.Parse("May 4, 2017") }; context.Messages.Add(message); context.Messages.Add(message2); context.SaveChanges(); } //Populates Interactions //if (!context.Interactions.Any()) //{ // Broker lonny = context.Brokers.First(); // StaffProfile profile = context.StaffProfiles.First(); // if (Helper.StaffProfileLoggedIn == null) // { // Helper.StaffProfileLoggedIn = profile; // } // Interaction i = new Interaction { Notes = "Interaction Numero Uno", NextStep = "Do the thing" }; // Interaction i1 = new Interaction { Notes = "Interaction: The seconding", NextStep = "Do the other thing" }; // context.Interactions.Add(i); // context.Interactions.Add(i1); // profile.Interactions.Add(i); // profile.Interactions.Add(i1); // lonny.Interactions.Add(i); // lonny.Interactions.Add(i1); // context.SaveChanges(); //} //Populates KWTasks if (!context.KWTasks.Any()) { StaffProfile profile = context.StaffProfiles.First(); KWTask kwt1 = new KWTask { Message = "A task to be accomplished", Priority = 3, Type = "Alert", DateDue = Convert.ToDateTime("4/22/2017") }; KWTask kwt2 = new KWTask { Message = "Enjoy your day", Priority = 5, Type = "Alert", DateDue = Convert.ToDateTime("4/12/2017") }; context.KWTasks.Add(kwt1); context.KWTasks.Add(kwt2); profile.Tasks.Add(kwt1); context.SaveChanges(); } }