public ActionResult Delete(Guid id, ViewModels.Tasks.TaskAssignedContactViewModel viewModel)
        {
            Common.Models.Account.Users             currentUser;
            Common.Models.Tasks.TaskAssignedContact currentModel;
            Common.Models.Tasks.TaskAssignedContact model;

            using (Data.Transaction trans = Data.Transaction.Create(true))
            {
                try
                {
                    currentUser = Data.Account.Users.Get(trans, User.Identity.Name);

                    currentModel = Data.Tasks.TaskAssignedContact.Get(trans, id);

                    model         = Mapper.Map <Common.Models.Tasks.TaskAssignedContact>(viewModel);
                    model.Contact = currentModel.Contact;
                    model.Task    = currentModel.Task;

                    model = Data.Tasks.TaskAssignedContact.Disable(trans, model, currentUser);

                    trans.Commit();

                    return(RedirectToAction("Contacts", "Tasks",
                                            new { id = model.Task.Id.Value.ToString() }));
                }
                catch
                {
                    trans.Rollback();
                    return(Delete(id));
                }
            }
        }
        public ActionResult AssignContact(int id)
        {
            Common.Models.Matters.Matter matter;
            Common.Models.Tasks.Task     task;
            long taskId = 0;

            ViewModels.Tasks.TaskAssignedContactViewModel vm;

            if (Request["TaskId"] == null)
            {
                return(View("InvalidRequest"));
            }

            if (!long.TryParse(Request["TaskId"], out taskId))
            {
                return(View("InvalidRequest"));
            }

            using (IDbConnection conn = Data.Database.Instance.GetConnection())
            {
                task   = Data.Tasks.Task.Get(taskId, conn, false);
                matter = Data.Tasks.Task.GetRelatedMatter(task.Id.Value, conn, false);

                vm         = new ViewModels.Tasks.TaskAssignedContactViewModel();
                vm.Task    = Mapper.Map <ViewModels.Tasks.TaskViewModel>(task);
                vm.Contact = Mapper.Map <ViewModels.Contacts.ContactViewModel>(
                    Data.Contacts.Contact.Get(id, conn, false));
                vm.AssignmentType = ViewModels.AssignmentTypeViewModel.Delegated;
            }

            ViewBag.Task   = task;
            ViewBag.Matter = matter;

            return(View(vm));
        }
        public ActionResult AssignContact(int id)
        {
            Common.Models.Matters.Matter matter;
            Common.Models.Tasks.Task task;
            long taskId = 0;
            ViewModels.Tasks.TaskAssignedContactViewModel vm;

            if (Request["TaskId"] == null)
                return View("InvalidRequest");

            if (!long.TryParse(Request["TaskId"], out taskId))
                return View("InvalidRequest");

            using (IDbConnection conn = Data.Database.Instance.GetConnection())
            {
                task = Data.Tasks.Task.Get(taskId, conn, false);
                matter = Data.Tasks.Task.GetRelatedMatter(task.Id.Value, conn, false);

                vm = new ViewModels.Tasks.TaskAssignedContactViewModel();
                vm.Task = Mapper.Map<ViewModels.Tasks.TaskViewModel>(task);
                vm.Contact = Mapper.Map<ViewModels.Contacts.ContactViewModel>(
                    Data.Contacts.Contact.Get(id, conn, false));
                vm.AssignmentType = ViewModels.AssignmentTypeViewModel.Delegated;
            }

            ViewBag.Task = task;
            ViewBag.Matter = matter;

            return View(vm);
        }
        public ActionResult AssignContact(int id)
        {
            Common.Models.Matters.Matter matter;
            Common.Models.Tasks.Task task;
            long taskId = 0;
            ViewModels.Tasks.TaskAssignedContactViewModel vm;

            if (Request["TaskId"] == null)
                return View("InvalidRequest");

            if (!long.TryParse(Request["TaskId"], out taskId))
                return View("InvalidRequest");

            task = Data.Tasks.Task.Get(taskId);
            matter = Data.Tasks.Task.GetRelatedMatter(task.Id.Value);

            vm = new ViewModels.Tasks.TaskAssignedContactViewModel();
            vm.Task = Mapper.Map<ViewModels.Tasks.TaskViewModel>(task);
            vm.Contact = Mapper.Map<ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(id));
            vm.AssignmentType = ViewModels.AssignmentTypeViewModel.Delegated;

            ViewData["Task"] = task.Title;
            ViewData["TaskId"] = task.Id;
            ViewData["Matter"] = matter.Title;
            ViewData["MatterId"] = matter.Id;

            return View(vm);
        }
        public ActionResult AssignContact(ViewModels.Tasks.TaskAssignedContactViewModel model)
        {
            Common.Models.Account.Users             currentUser;
            Common.Models.Tasks.TaskAssignedContact taskContact;

            // We need to reset the Id of the model as it is picking up the id from the route,
            // which is incorrect
            model.Id = null;

            currentUser = Data.Account.Users.Get(User.Identity.Name);

            taskContact = Data.Tasks.TaskAssignedContact.Get(model.Task.Id.Value, model.Contact.Id.Value);

            if (taskContact == null)
            { // Create
                taskContact = Mapper.Map <Common.Models.Tasks.TaskAssignedContact>(model);
                taskContact = Data.Tasks.TaskAssignedContact.Create(taskContact, currentUser);
            }
            else
            { // Enable
                taskContact = Mapper.Map <Common.Models.Tasks.TaskAssignedContact>(model);
                taskContact = Data.Tasks.TaskAssignedContact.Enable(taskContact, currentUser);
            }

            return(RedirectToAction("Contacts", "Tasks",
                                    new { id = taskContact.Task.Id.Value.ToString() }));
        }
        public ActionResult AssignContact(int id)
        {
            Common.Models.Matters.Matter matter;
            Common.Models.Tasks.Task     task;
            long taskId = 0;

            ViewModels.Tasks.TaskAssignedContactViewModel vm;

            if (Request["TaskId"] == null)
            {
                return(View("InvalidRequest"));
            }

            if (!long.TryParse(Request["TaskId"], out taskId))
            {
                return(View("InvalidRequest"));
            }

            task   = Data.Tasks.Task.Get(taskId);
            matter = Data.Tasks.Task.GetRelatedMatter(task.Id.Value);

            vm                = new ViewModels.Tasks.TaskAssignedContactViewModel();
            vm.Task           = Mapper.Map <ViewModels.Tasks.TaskViewModel>(task);
            vm.Contact        = Mapper.Map <ViewModels.Contacts.ContactViewModel>(Data.Contacts.Contact.Get(id));
            vm.AssignmentType = ViewModels.AssignmentTypeViewModel.Delegated;

            ViewData["Task"]     = task.Title;
            ViewData["TaskId"]   = task.Id;
            ViewData["Matter"]   = matter.Title;
            ViewData["MatterId"] = matter.Id;

            return(View(vm));
        }
Exemplo n.º 7
0
        public ActionResult Delete(Guid id, ViewModels.Tasks.TaskAssignedContactViewModel viewModel)
        {
            Common.Models.Account.Users currentUser;
            Common.Models.Events.EventAssignedContact currentModel;
            Common.Models.Events.EventAssignedContact model;

            currentUser = Data.Account.Users.Get(User.Identity.Name);

            currentModel = Data.Events.EventAssignedContact.Get(id);

            model         = Mapper.Map <Common.Models.Events.EventAssignedContact>(viewModel);
            model.Contact = currentModel.Contact;
            model.Event   = currentModel.Event;

            model = Data.Events.EventAssignedContact.Disable(model, currentUser);

            return(RedirectToAction("Contacts", "Events",
                                    new { id = model.Event.Id.Value.ToString() }));
        }
        public ActionResult AssignContact(ViewModels.Tasks.TaskAssignedContactViewModel model)
        {
            Common.Models.Account.Users             currentUser;
            Common.Models.Tasks.TaskAssignedContact taskContact;

            // We need to reset the Id of the model as it is picking up the id from the route,
            // which is incorrect
            model.Id = null;

            using (Data.Transaction trans = Data.Transaction.Create(true))
            {
                try
                {
                    currentUser = Data.Account.Users.Get(trans, User.Identity.Name);

                    taskContact = Data.Tasks.TaskAssignedContact.Get(trans, model.Task.Id.Value, model.Contact.Id.Value);

                    if (taskContact == null)
                    { // Create
                        taskContact = Mapper.Map <Common.Models.Tasks.TaskAssignedContact>(model);
                        taskContact = Data.Tasks.TaskAssignedContact.Create(trans, taskContact, currentUser);
                    }
                    else
                    { // Enable
                        Guid id = taskContact.Id.Value;
                        taskContact    = Mapper.Map <Common.Models.Tasks.TaskAssignedContact>(model);
                        taskContact.Id = id;
                        taskContact    = Data.Tasks.TaskAssignedContact.Enable(trans, taskContact, currentUser);
                    }

                    trans.Commit();

                    return(RedirectToAction("Contacts", "Tasks",
                                            new { id = taskContact.Task.Id.Value.ToString() }));
                }
                catch (Exception e)
                {
                    trans.Rollback();
                    return(AssignContact(model.Contact.Id.Value));
                }
            }
        }