Exemple #1
0
        public IActionResult InteractionEdit(Interaction i)
        {
            if (i != null)
            {
                Interaction interaction = intRepo.GetInteractionById(i.InteractionID);
                interaction.Notes       = i.Notes;
                interaction.DateCreated = i.DateCreated;
                interaction.NextStep    = i.NextStep;
                interaction.Status      = i.Status;

                int verify = intRepo.UpdateInteraction(interaction);
                if (verify == 1)
                {
                    //TODO add feedback of success
                    return(RedirectToAction("Interactions"));
                }
                else
                {
                    //TODO add feedback for error
                }
            }
            else
            {
                ModelState.AddModelError("", "Interaction Not Found");
            }
            return(View(i));
        }
        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 }));
        }