Exemple #1
0
        public ActionResult Create(ViewModels.Events.EventResponsibleUserViewModel viewModel)
        {
            Common.Models.Events.EventResponsibleUser model;
            Common.Models.Account.Users currentUser;
            Common.Models.Events.EventResponsibleUser currentResponsibleUser;
            List <ViewModels.Account.UsersViewModel>  userViewModelList;

            Common.Models.Events.Event       evnt;
            ViewModels.Events.EventViewModel eventViewModel;

            model       = Mapper.Map <Common.Models.Events.EventResponsibleUser>(viewModel);
            currentUser = Data.Account.Users.Get(User.Identity.Name);

            // Is there already an entry for this user?
            currentResponsibleUser = Data.Events.EventResponsibleUser.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.");

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

                    evnt = Data.Events.Event.Get(currentResponsibleUser.Event.Id.Value);

                    eventViewModel = Mapper.Map <ViewModels.Events.EventViewModel>(evnt);

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

                    ViewData["UserList"] = userViewModelList;

                    return(View(new ViewModels.Events.EventResponsibleUserViewModel()
                    {
                        Event = eventViewModel
                    }));
                }

                model.Id             = currentResponsibleUser.Id;
                model.Responsibility = model.Responsibility;

                // Remove disability
                model = Data.Events.EventResponsibleUser.Enable(model, currentUser);

                // Update responsibility
                model = Data.Events.EventResponsibleUser.Edit(model, currentUser);
            }
            else
            { // Insert
                model = Data.Events.EventResponsibleUser.Create(model, currentUser);
            }

            return(RedirectToAction("ResponsibleUsers", "Events", new { Id = model.Event.Id.Value.ToString() }));
        }
Exemple #2
0
        public ActionResult Delete(Guid id, ViewModels.Events.EventResponsibleUserViewModel viewModel)
        {
            Common.Models.Account.Users currentUser;
            Common.Models.Events.EventResponsibleUser model;

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

            model = Data.Events.EventResponsibleUser.Get(id);

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

            return(RedirectToAction("ResponsibleUsers", "Events", new { Id = model.Event.Id.Value }));
        }
        public ActionResult ResponsibleUsers(Guid id)
        {
            List <ViewModels.Events.EventResponsibleUserViewModel> list;

            list = new List <ViewModels.Events.EventResponsibleUserViewModel>();

            Data.Events.EventResponsibleUser.ListForEvent(id).ForEach(x =>
            {
                ViewModels.Events.EventResponsibleUserViewModel vm = Mapper.Map <ViewModels.Events.EventResponsibleUserViewModel>(x);
                vm.User = Mapper.Map <ViewModels.Account.UsersViewModel>(Data.Account.Users.Get(x.User.PId.Value));
                list.Add(vm);
            });

            return(View(list));
        }