Esempio n. 1
0
        public async Task<ActionResult> Edit(UserProfileEdit userProfileEdit, CancellationToken cancellationToken)
        {
            if (!IsAccess(userProfileEdit.UserId))
            {
                return RedirectToAccessDenied();
            }

            ModelState.Merge(await userProfileEdit.Validate(Db, this, cancellationToken, IsAdmin));

            if (ModelState.IsValid)
            {
                UserProfile userProfile;
                bool success = UserProfileCache.Update(Db, userProfileEdit, IsAdmin, out userProfile);
                if (!success)
                {
                    return RedirectToAccessDenied();
                }

                return RedirectToAction("Index");
            }

            PopulateRole(userProfileEdit.Role);
            PopulateDistrictId(userProfileEdit.DistrictId);
            PopulatePhoneNumberPrefix1Id(userProfileEdit.PhoneNumberPrefix1Id);
            PopulatePhoneNumberPrefix2Id(userProfileEdit.PhoneNumberPrefix2Id);
            PopulateClaAccessChangedCurrency(userProfileEdit.ClaAccessAmount, userProfileEdit.ClaAccessCurrency, userProfileEdit.ClaAccessCurrency);

            return View(userProfileEdit);
        }
Esempio n. 2
0
        public static bool Update(DefaultContext db, UserProfileEdit userProfileEdit, bool isAdmin, out UserProfile userProfile)
        {
            userProfile = null;

            UserProfile dbUserProfile = GetDetail(db, userProfileEdit.UserId);
            if (dbUserProfile == null)
                return false;

            dbUserProfile.CopyFrom(userProfileEdit, isAdmin);
            db.SaveChanges();

            userProfile = dbUserProfile;

            if (!isAdmin)
                return true;

            ChangeUserRole(dbUserProfile.UserName, userProfileEdit.Role);

            return true;
        }
Esempio n. 3
0
        public ActionResult Edit(int id = 0)
        {
            UserProfile userProfile = UserProfileCache.GetDetail(Db, id);
            if (!IsEditable(userProfile, id))
            {
                return RedirectToAccessDenied();
            }

            var userProfileEdit = new UserProfileEdit(userProfile);

            PopulateRole(userProfile.Role);
            PopulateDistrictId(userProfile.DistrictId);
            PopulatePhoneNumberPrefix1Id(userProfile.PhoneNumberPrefix1Id);
            PopulatePhoneNumberPrefix2Id(userProfile.PhoneNumberPrefix2Id);
            PopulateClaAccessChangedCurrency(userProfile.ClaAccessAmount, userProfile.ClaAccessCurrency, userProfile.ClaAccessCurrency);

            return View(userProfileEdit);
        }
Esempio n. 4
0
        public void CopyFrom(UserProfileEdit userProfileEdit, bool isAdmin)
        {
            CopyFrom(userProfileEdit);

            PremiumMembershipGranted = userProfileEdit.PremiumMembershipGranted;
            Ca = userProfileEdit.Ca;
            MspCoach = userProfileEdit.MspCoach;
            Presenting = userProfileEdit.Presenting;

            if (!isAdmin)
                return;

            ClaAccessAmount = userProfileEdit.ClaAccessAmount;
            ClaAccessCurrency = userProfileEdit.ClaAccessCurrency;
            SetClaAccessYearlyAccess(userProfileEdit.ClaAccessCurrency, userProfileEdit.ClaAccessYearlyAccess);
        }