Beispiel #1
0
        public ActionResult Edit(AppUserEditView model)
        {
            if (ModelState.IsValid)
            {
                if (Request.Form["submitbutton"] != null)
                {
                    AppUserHelpers.UpdateAppUserFromAppUserEditView(db, model);
                    return(RedirectToAction(model.CallingAction, model.CallingController));
                }

                return(RedirectToAction("Edit"));
            }

            Branch userBranch = BranchHelpers.GetCurrentBranchForUser(AppUserHelpers.GetGuidFromUserGetAppUserId(User.Identity.GetAppUserId()));

            //DropDowns
            ViewBag.BranchList       = ControlHelpers.AllBranchesForCompanyListDropDown(userBranch.CompanyId, userBranch.BranchId);
            ViewBag.UserRoleList     = ControlHelpers.UserRoleEnumListDropDown();
            ViewBag.EntityStatusList = ControlHelpers.EntityStatusEnumListDropDown();

            //Counters
            if (model.UserFriendListView == null)
            {
                model.UserFriendListView = new List <FriendView>();
            }
            if (model.UserBranchFriendListView == null)
            {
                model.UserBranchFriendListView = new List <FriendView>();
            }
            if (model.UserCompanyFriendListView == null)
            {
                model.UserCompanyFriendListView = new List <FriendView>();
            }

            ViewBag.UserFriendCount        = model.UserFriendListView.Count();
            ViewBag.UserBranchFriendCount  = model.UserBranchFriendListView.Count();
            ViewBag.UserCompanyFriendCount = model.UserCompanyFriendListView.Count();

            if (model.UserBlockListView == null)
            {
                model.UserBlockListView = new List <BlockView>();
            }
            if (model.UserBranchBlockListView == null)
            {
                model.UserBranchBlockListView = new List <BlockView>();
            }
            if (model.UserCompanyBlockListView == null)
            {
                model.UserCompanyBlockListView = new List <BlockView>();
            }

            ViewBag.UserBlockCount        = model.UserBlockListView.Count();
            ViewBag.UserBranchBlockCount  = model.UserBranchBlockListView.Count();
            ViewBag.UserCompanyBlockCount = model.UserCompanyBlockListView.Count();

            //rebuild group model
            model.GroupListViewsForUserOnly = GroupViewHelpers.GetGroupEditViewForForUserOnly(db, model.AppUserId);

            return(View(model));
        }
Beispiel #2
0
        public async Task <ActionResult> Create(AppUserView model)
        {
            if (ModelState.IsValid)
            {
                //initialise the task creation flags
                bool createUserOnHoldTask = false;

                //Retrieve Branch
                Branch branch = BranchHelpers.GetBranch(db, model.SelectedBranchId.Value);

                //Create a new AppUser then write here
                AppUser appUser = AppUserHelpers.CreateAppUser(model.FirstName, model.LastName, branch.BranchId, model.EntityStatus, model.Email, model.PrivacyLevel, model.UserRole);

                BranchUser branchUser = null;

                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, AppUserId = appUser.AppUserId, FullName = model.FirstName + " " + model.LastName, CurrentUserRole = model.UserRole
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //set on-hold task flag
                    if (model.EntityStatus == EntityStatusEnum.OnHold)
                    {
                        createUserOnHoldTask = true;
                    }

                    //Now Update related entities
                    //BranchUser - set the status as ACTIVE as the link is active even though the entities linked are not.
                    branchUser = BranchUserHelpers.CreateBranchUser(appUser.AppUserId, branch.BranchId, branch.CompanyId, model.UserRole, EntityStatusEnum.Active);

                    //Task creation
                    if (createUserOnHoldTask)
                    {
                        UserTaskHelpers.CreateUserTask(TaskTypeEnum.UserOnHold, "New user on hold, awaiting administrator/manager activation", appUser.AppUserId, appUser.AppUserId, EntityStatusEnum.Active);
                    }

                    return(RedirectToAction("UserAdmin", "Admin"));
                }

                //Delete the appUser account as this has not gone through
                AppUserHelpers.DeleteAppUser(appUser.AppUserId);
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form - set up the drop downs dependant on what was there originally from the model
            Branch userBranch = BranchHelpers.GetCurrentBranchForUser(AppUserHelpers.GetGuidFromUserGetAppUserId(User.Identity.GetAppUserId()));

            //DropDown
            ViewBag.BranchList       = ControlHelpers.AllBranchesForCompanyListDropDown(userBranch.CompanyId, userBranch.BranchId);
            ViewBag.UserRoleList     = ControlHelpers.UserRoleEnumListDropDown();
            ViewBag.EntityStatusList = ControlHelpers.EntityStatusEnumListDropDown();

            return(View(model));
        }
Beispiel #3
0
        // GET: AppUsers/Create
        public ActionResult Create()
        {
            Branch userBranch = BranchHelpers.GetCurrentBranchForUser(AppUserHelpers.GetGuidFromUserGetAppUserId(User.Identity.GetAppUserId()));

            //DropDowns
            ViewBag.BranchList       = ControlHelpers.AllBranchesForCompanyListDropDown(userBranch.CompanyId, userBranch.BranchId);
            ViewBag.UserRoleList     = ControlHelpers.UserRoleEnumListDropDown();
            ViewBag.EntityStatusList = ControlHelpers.EntityStatusEnumListDropDown();

            return(View());
        }
Beispiel #4
0
        // GET: AppUsers/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            string callingController = "Home";
            string callingAction     = "Index";

            try
            {
                string[] callingUrlSegments = Request.UrlReferrer.Segments.Select(x => x.TrimEnd('/')).ToArray();
                callingController = callingUrlSegments[callingUrlSegments.Count() - 2];
                callingAction     = callingUrlSegments[callingUrlSegments.Count() - 1];
            }
            catch { }

            AppUserEditView model = AppUserEditViewHelpers.GetAppUserEditViewForUser(db, User);

            model.CallingAction     = callingAction;
            model.CallingController = callingController;

            Branch userBranch = BranchHelpers.GetCurrentBranchForUser(AppUserHelpers.GetGuidFromUserGetAppUserId(User.Identity.GetAppUserId()));

            //DropDowns
            ViewBag.BranchList       = ControlHelpers.AllBranchesForCompanyListDropDown(userBranch.CompanyId, userBranch.BranchId);
            ViewBag.UserRoleList     = ControlHelpers.UserRoleEnumListDropDown();
            ViewBag.EntityStatusList = ControlHelpers.EntityStatusEnumListDropDown();

            //Counters
            ViewBag.UserFriendCount        = model.UserFriendListView.Count();
            ViewBag.UserBranchFriendCount  = model.UserBranchFriendListView.Count();
            ViewBag.UserCompanyFriendCount = model.UserCompanyFriendListView.Count();

            ViewBag.UserBlockCount        = model.UserBlockListView.Count();
            ViewBag.UserBranchBlockCount  = model.UserBranchBlockListView.Count();
            ViewBag.UserCompanyBlockCount = model.UserCompanyBlockListView.Count();

            if (model == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }