Пример #1
0
        public IActionResult AdminStaff()
        {
            ViewBag.Page = "Staff";
            var vm = new AdminVM();

            vm.Staff    = staffRepo.GetAllStaffProfiles().ToList();
            vm.NewStaff = new StaffProfile();
            //TODO Ensure user is rerouted if not logged in
            return(View("AdminHome", vm));
        }
Пример #2
0
        //[Route("Index")]
        public IActionResult AllKWTasks(string filter)
        {
            /*Call the GetToday method of the helper class to get and set today's date for use with datepicker validation*/
            Helper.GetToday();

            var criticalVB = taskRepo.GetAllTasksByType("Alert").Where(t => t.Priority == 5).ToList();

            foreach (KWTask task in taskRepo.GetAllTasksByType("Task").Where(t => t.Priority == 5).ToList())
            {
                criticalVB.Add(task);
            }

            ViewBag.Critical = criticalVB;

            ViewBag.Filter = filter;
            var vm = new KWTaskVM();

            vm.StaffList = staffRepo.GetAllStaffProfiles().ToList();
            var KWTasks = taskRepo.GetAllKWTasks().Where(t => t.Type != "Onboarding").ToList();

            foreach (KWTask t in KWTasks.ToList())
            {
                if (t.Priority == 5)
                {
                    StaffProfile profile = staffRepo.GetProfileByTask(t);
                    if (profile != null)
                    {
                        profile.Tasks.Remove(t);
                        staffRepo.UpdateStaff(profile);
                    }
                }
                foreach (StaffProfile s in vm.StaffList)
                {
                    if (s.Tasks.Contains(t))
                    {
                        t.StaffName  = s.FirstName + " " + s.LastName;
                        t.StaffEmail = s.Email;
                    }
                }
            }
            vm.KWTasks   = KWTasks;
            vm.NewKWTask = new KWTask();
            return(View(vm));
        }
Пример #3
0
        public static StaffProfile DetermineProfile(IStaffProfileRepository adbc)
        {
            StaffProfile stafProf = new Models.StaffProfile();

            var profList = adbc.GetAllStaffProfiles();

            stafProf = (from sp in profList
                        where sp.User.Id == StaffUserLoggedIn.Id
                        select sp).Include(s => s.Tasks).Include(s => s.Interactions).FirstOrDefault <StaffProfile>();

            return(stafProf);
        }
Пример #4
0
        public IActionResult BrokerInteractions(int BrokerID)
        {
            /*Call the GetToday method of the helper class to get and set today's date for use with datepicker validation*/
            Helper.GetToday();

            ViewBag.Critical = taskRepo.GetAllTasksByType("Alert").Where(t => t.Priority == 5).ToList();
            var broker = brokerRepo.GetBrokerByID(BrokerID);

            ViewBag.BrokerName      = broker.FirstName + " " + broker.LastName;
            ViewBag.CurrentBrokerID = broker.BrokerID;
            ViewBag.StaffEmail      = Helper.StaffProfileLoggedIn.Email;
            var allInteractions = broker.Interactions; //This is where the issue seems to present
            var vm = new InteractionVM();

            vm.Interactions   = allInteractions;
            vm.Broker         = broker;
            vm.NewInteraction = new Interaction();
            vm.AllBrokers     = brokerRepo.GetAllBrokers().ToList();
            vm.Task           = new KWTask();
            vm.TasksCompleted = 0;
            vm.AllStaff       = staffRepo.GetAllStaffProfiles().ToList();

            List <KWTask> tasks = new List <KWTask>();

            foreach (KWTask t in broker.Requirements)
            {
                tasks.Add(t);
                if (t.IsComplete)
                {
                    vm.TasksCompleted++;
                }
            }
            ViewBag.Percent = Math.Round((vm.TasksCompleted / 16) * 100);

            foreach (Interaction i in broker.Interactions)
            {
                if (i.TaskForeignKey != null)
                {
                    tasks.Add(taskRepo.GetKWTaskByID((int)i.TaskForeignKey));
                }
            }
            vm.Tasks = tasks;
            //TODO Ensure user is rerouted if not logged in
            return(View(vm));
        }
Пример #5
0
        public async Task <IActionResult> Index()
        {
            /*Login Logic*/
            StaffUser user = await userManager.FindByNameAsync(User.Identity.Name);

            Helper.StaffUserLoggedIn    = user;
            Helper.StaffProfileLoggedIn = Helper.DetermineProfile(staffProfRepo);
            /*End Login Logic*/

            /*Call the GetToday method of the helper class to get and set today's date for use with datepicker validation*/
            Helper.GetToday();

            /* Priority reassignment Logic */
            var tasks = taskRepo.GetAllKWTasks().Where(t => t.Type != "Onboarding");


            foreach (KWTask t in tasks.ToList())
            {
                int diff = (int)(t.DateDue - DateTime.Today).Value.TotalDays;
                if (diff < 0 && t.Priority < 5)
                {
                    StaffProfile profile = staffProfRepo.GetProfileByTask(t);

                    t.Priority = 5;
                    taskRepo.UpdateKWTask(t);

                    if (profile != null)
                    {
                        profile.Tasks.Remove(t);
                        staffProfRepo.UpdateStaff(profile);
                    }
                }
                else if (diff == 0 && t.Priority < 4)
                {
                    t.Priority = 4;
                    taskRepo.UpdateKWTask(t);
                }

                else if (diff <= 2 && t.Priority < 3)
                {
                    t.Priority = 3;
                    taskRepo.UpdateKWTask(t);
                }

                else if (diff == 3 && t.Priority < 2)
                {
                    t.Priority = 2;
                    taskRepo.UpdateKWTask(t);
                }
            }



            /*Display Alerts Logic*/
            ViewBag.Name   = Helper.StaffProfileLoggedIn.FirstName;
            ViewBag.Alerts = Helper.StaffProfileLoggedIn.Tasks.Where(
                t => t.Type == "Alert" &&
                (DateTime.Compare(DateTime.Now, t.AlertDate.GetValueOrDefault()) == 0 ||
                 DateTime.Compare(DateTime.Now, t.AlertDate.GetValueOrDefault()) > 0)).ToList();

            var criticalVB = taskRepo.GetAllTasksByType("Alert").Where(t => t.Priority == 5).ToList();

            foreach (KWTask task in taskRepo.GetAllTasksByType("Task").Where(t => t.Priority == 5).ToList())
            {
                criticalVB.Add(task);
            }

            ViewBag.Critical = criticalVB;

            /*End Display Alerts Logic*/

            /*Populate ViewModel Logic*/
            var vm = new HomeVM();

            /*TODO Be aware this directly queries the database, may break if StaffProfile or KWTask models change*/
            string sqlGlobal   = "SELECT * FROM dbo.KWTasks WHERE StaffProfileID IS NULL";
            string sqlPersonal = "SELECT * FROM dbo.KWTasks WHERE StaffProfileID = " + Helper.StaffProfileLoggedIn.StaffProfileID;

            vm.GlobalTasks   = taskRepo.GetTasksFromSQL(sqlGlobal).Where(t => t.Type != "Onboarding").ToList();
            vm.PersonalTasks = taskRepo.GetTasksFromSQL(sqlPersonal).Where(t => t.Type != "Onboarding").ToList();

            List <Broker> brokers = new List <Broker>();

            foreach (Interaction i in Helper.StaffProfileLoggedIn.Interactions)
            {
                foreach (Broker b in brokerRepo.GetAllBrokers())
                {
                    if (b.Interactions.Contains(i))
                    {
                        i.BrokerName = b.FirstName + " " + b.LastName;

                        if (!brokers.Contains(b))
                        {
                            brokers.Add(b);
                        }
                    }
                }
            }
            ViewBag.Brokers = brokers;


            vm.PersonalInteractions = Helper.StaffProfileLoggedIn.Interactions;
            vm.NewTask    = new KWTask();
            vm.NewBroker  = new Broker();
            vm.NewMessage = new Message();
            vm.StaffList  = staffProfRepo.GetAllStaffProfiles().ToList();
            /*End Populate ViewModel Logic*/

            return(View(vm));
        }
Пример #6
0
        public IActionResult SendMessage(Message m, string returnURL, bool checkAll = false, bool checkAllBrokers = false, bool checkStaff = false,
                                         bool checkNewBrokers = false, bool checkBrokersInTransition = false, bool checkTransferBrokers    = false)
        {
            var message = new Message
            {
                Subject  = m.Subject,
                Body     = m.Body,
                DateSent = DateTime.Now,
            };


            messageRepo.AddMessage(message);

            if (checkAll == true)
            {
                brokers = brokerRepo.GetAllBrokers(false, true);
                staff   = staffRepo.GetAllStaffProfiles(true);
            }
            else
            {
                if (checkAllBrokers == true)
                {
                    brokers = brokerRepo.GetAllBrokers(false, true);
                }
                else
                {
                    if (checkNewBrokers == true)
                    {
                        if (brokers != null)
                        {
                            var newBrokers = brokerRepo.GetBrokersByType("New Broker", true);
                            foreach (var b in newBrokers)
                            {
                                brokers.Append(b);
                            }
                        }
                        else
                        {
                            brokers = brokerRepo.GetBrokersByType("New Broker", true);
                        }
                    }

                    if (checkBrokersInTransition == true)
                    {
                        if (brokers != null)
                        {
                            var transitionBrokers = brokerRepo.GetBrokersByType("In Transition", true);
                            foreach (var b in transitionBrokers)
                            {
                                brokers.Append(b);
                            }
                        }
                        else
                        {
                            brokers = brokerRepo.GetBrokersByType("In Transition", true);
                        }
                    }
                    if (checkTransferBrokers == true)
                    {
                        if (brokers != null)
                        {
                            var transferBrokers = brokerRepo.GetBrokersByType("Transfer", true);
                            foreach (var b in transferBrokers)
                            {
                                brokers.Append(b);
                            }
                        }
                        else
                        {
                            brokers = brokerRepo.GetBrokersByType("Transfer", true);
                        }
                    }
                }
                if (checkStaff == true)
                {
                    staff = staffRepo.GetAllStaffProfiles(true);
                }
            }
            var email = new MimeMessage();

            email.From.Add(new MailboxAddress("KWFCI", "*****@*****.**"));
            email.Subject = message.Subject;
            email.Body    = new TextPart("plain")
            {
                Text = message.Body
            };
            if (brokers != null)
            {
                foreach (var b in brokers)
                {
                    email.Bcc.Add(new MailboxAddress(b.FirstName + " " + b.LastName, b.Email));
                }
            }

            if (staff != null)
            {
                foreach (var st in staff)
                {
                    email.Bcc.Add(new MailboxAddress(st.FirstName + " " + st.LastName, st.Email));
                }
            }
            using (var client = new SmtpClient())
            {
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;

                client.Connect("smtp.gmail.com", 587, false);

                client.AuthenticationMechanisms.Remove("XOAUTH2");
                client.Authenticate("kwfamilycheckin", "Fancy123!");

                client.Send(email);
                client.Disconnect(true);
            }



            return(Redirect(returnURL));
        }