Example #1
0
        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(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 }));
        }