Пример #1
0
        public ActionResult Delete(int id, ViewModels.Matters.ResponsibleUserViewModel viewModel)
        {
            Common.Models.Account.Users           currentUser;
            Common.Models.Matters.ResponsibleUser model;

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

            model = Mapper.Map <Common.Models.Matters.ResponsibleUser>(viewModel);

            model = Data.Matters.ResponsibleUser.Disable(model, currentUser);

            return(RedirectToAction("ResponsibleUsers", "Matters", new { Id = model.Matter.Id.Value }));
        }
Пример #2
0
        public ActionResult Create(ViewModels.Matters.ResponsibleUserViewModel viewModel)
        {
            Common.Models.Account.Users              currentUser;
            Common.Models.Matters.ResponsibleUser    model;
            Common.Models.Matters.ResponsibleUser    currentResponsibleUser;
            List <ViewModels.Account.UsersViewModel> userViewModelList;

            Common.Models.Matters.Matter       matter;
            ViewModels.Matters.MatterViewModel matterViewModel;

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

            model        = Mapper.Map <Common.Models.Matters.ResponsibleUser>(viewModel);
            model.Matter = new Common.Models.Matters.Matter()
            {
                Id = Guid.Parse(RouteData.Values["Id"].ToString())
            };

            // Is there already an entry for this user?
            currentResponsibleUser = Data.Matters.ResponsibleUser.GetIgnoringDisable(
                Guid.Parse(RouteData.Values["Id"].ToString()), currentUser.PId.Value);

            if (currentResponsibleUser != null)
            { // Update
                if (!currentResponsibleUser.Disabled.HasValue)
                {
                    ModelState.AddModelError("User", "This user already has a responsibility.");

                    matter = Data.Matters.Matter.Get(currentResponsibleUser.Matter.Id.Value);

                    matterViewModel = Mapper.Map <ViewModels.Matters.MatterViewModel>(matter);

                    userViewModelList = new List <ViewModels.Account.UsersViewModel>();

                    Data.Account.Users.List().ForEach(x =>
                    {
                        userViewModelList.Add(Mapper.Map <ViewModels.Account.UsersViewModel>(x));
                    });

                    ViewData["UserList"] = userViewModelList;

                    ViewData["MatterId"] = matter.Id.Value;
                    ViewData["Matter"]   = matter.Title;
                    return(View(new ViewModels.Matters.ResponsibleUserViewModel()
                    {
                        Matter = matterViewModel
                    }));
                }

                // Remove disability
                model = Data.Matters.ResponsibleUser.Enable(model, currentUser);

                // Update responsibility
                model.Responsibility = model.Responsibility;
                model = Data.Matters.ResponsibleUser.Edit(model, currentUser);
            }
            else
            { // Insert
                model = Data.Matters.ResponsibleUser.Create(model, currentUser);
            }

            return(RedirectToAction("ResponsibleUsers", "Matters", new { Id = model.Matter.Id.Value.ToString() }));
        }