Exemple #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));
        }
Exemple #2
0
        public static AppUserEditView GetAppUserEditViewForUser(AppUser appUserDetails)
        {
            ApplicationDbContext db   = new ApplicationDbContext();
            AppUserEditView      view = GetAppUserEditViewForUser(db, appUserDetails);

            db.Dispose();
            return(view);
        }
Exemple #3
0
        public static AppUserEditView GetAppUserEditViewForUser(IPrincipal user)
        {
            ApplicationDbContext db   = new ApplicationDbContext();
            AppUserEditView      view = GetAppUserEditViewForUser(db, user);

            db.Dispose();
            return(view);
        }
Exemple #4
0
        public static AppUser UpdateAppUserFromAppUserEditView(AppUserEditView view)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            AppUser appUser         = UpdateAppUserFromAppUserEditView(db, view);

            db.Dispose();
            return(appUser);
        }
Exemple #5
0
        public static AppUserSettings UpdateUserSettingsFromAppUserEditView(AppUserEditView view)
        {
            ApplicationDbContext db       = new ApplicationDbContext();
            AppUserSettings      settings = UpdateUserSettingsFromAppUserEditView(db, view);

            db.Dispose();
            return(settings);
        }
Exemple #6
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));
        }
Exemple #7
0
        public static AppUserEditView GetAppUserEditViewForUser(ApplicationDbContext db, AppUser appUserDetails)
        {
            Branch     branch     = BranchHelpers.GetBranch(db, appUserDetails.CurrentBranchId);
            BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, appUserDetails.AppUserId, appUserDetails.CurrentBranchId);

            AppUserSettings appUserSettings = AppUserSettingsHelpers.GetAppUserSettingsForUser(db, appUserDetails.AppUserId);

            AppUserEditView view = new AppUserEditView()
            {
                AppUserId                                           = appUserDetails.AppUserId,
                FirstName                                           = appUserDetails.FirstName,
                LastName                                            = appUserDetails.LastName,
                EntityStatus                                        = appUserDetails.EntityStatus,
                PrivacyLevel                                        = appUserDetails.PrivacyLevel,
                SelectedBranchId                                    = appUserDetails.CurrentBranchId,
                UserRole                                            = branchUser.UserRole,
                AppUserSettingsId                                   = appUserSettings.AppUserSettingsId,
                BranchName                                          = branch.BranchName,
                BranchBusinessType                                  = branch.BusinessType,
                BranchAddressLine1                                  = branch.AddressLine1,
                BranchAddressLine2                                  = branch.AddressLine2,
                BranchAddressLine3                                  = branch.AddressLine3,
                BranchAddressTownCity                               = branch.AddressTownCity,
                BranchAddressCounty                                 = branch.AddressCounty,
                BranchAddressPostcode                               = branch.AddressPostcode,
                CampaignDashboardMaxDistance                        = appUserSettings.CampaignDashboardMaxDistance,
                CampaignDashboardMaxAge                             = appUserSettings.CampaignDashboardMaxAge,
                RequiredListingDashboardMaxDistance                 = appUserSettings.RequiredListingDashboardMaxDistance,
                RequiredListingDashboardMaxAge                      = appUserSettings.RequiredListingDashboardMaxAge,
                AvailableListingDashboardMaxDistance                = appUserSettings.AvailableListingDashboardMaxDistance,
                AvailableListingDashboardMaxAge                     = appUserSettings.AvailableListingDashboardMaxAge,
                CampaignDashboardExternalSelectionLevel             = appUserSettings.CampaignDashboardExternalSelectionLevel,
                RequiredListingDashboardExternalSelectionLevel      = appUserSettings.RequiredListingDashboardExternalSelectionLevel,
                AvailableListingDashboardExternalSelectionLevel     = appUserSettings.AvailableListingDashboardExternalSelectionLevel,
                CampaignGeneralInfoDisplayMyUserListings            = appUserSettings.CampaignGeneralInfoDisplayMyUserListings,
                CampaignGeneralInfoDisplayMyBranchListings          = appUserSettings.CampaignGeneralInfoDisplayMyBranchListings,
                CampaignGeneralInfoDisplayMyCompanyListings         = appUserSettings.CampaignGeneralInfoDisplayMyCompanyListings,
                CampaignGeneralInfoDisplayBlockedListings           = appUserSettings.CampaignGeneralInfoDisplayBlockedListings,
                CampaignGeneralInfoMaxDistance                      = appUserSettings.CampaignGeneralInfoMaxDistance,
                RequiredListingGeneralInfoDisplayMyUserListings     = appUserSettings.RequiredListingGeneralInfoDisplayMyUserListings,
                RequiredListingGeneralInfoDisplayMyBranchListings   = appUserSettings.RequiredListingGeneralInfoDisplayMyBranchListings,
                RequiredListingGeneralInfoDisplayMyCompanyListings  = appUserSettings.RequiredListingGeneralInfoDisplayMyCompanyListings,
                RequiredListingGeneralInfoDisplayBlockedListings    = appUserSettings.RequiredListingGeneralInfoDisplayBlockedListings,
                RequiredListingGeneralInfoMaxDistance               = appUserSettings.RequiredListingGeneralInfoMaxDistance,
                AvailableListingGeneralInfoDisplayMyUserListings    = appUserSettings.AvailableListingGeneralInfoDisplayMyUserListings,
                AvailableListingGeneralInfoDisplayMyBranchListings  = appUserSettings.AvailableListingGeneralInfoDisplayMyBranchListings,
                AvailableListingGeneralInfoDisplayMyCompanyListings = appUserSettings.AvailableListingGeneralInfoDisplayMyCompanyListings,
                AvailableListingGeneralInfoDisplayBlockedListings   = appUserSettings.AvailableListingGeneralInfoDisplayBlockedListings,
                AvailableListingGeneralInfoMaxDistance              = appUserSettings.AvailableListingGeneralInfoMaxDistance,
                CampaignManageViewInternalSelectionLevel            = appUserSettings.CampaignManageViewInternalSelectionLevel,
                RequiredListingManageViewInternalSelectionLevel     = appUserSettings.RequiredListingManageViewInternalSelectionLevel,
                AvailableListingManageViewInternalSelectionLevel    = appUserSettings.AvailableListingManageViewInternalSelectionLevel,
                OffersManageViewInternalSelectionLevel              = appUserSettings.OffersManageViewInternalSelectionLevel,
                OffersAcceptedAuthorisationManageViewLevel          = appUserSettings.OffersAcceptedAuthorisationManageViewLevel,
                OffersRejectedAuthorisationManageViewLevel          = appUserSettings.OffersRejectedAuthorisationManageViewLevel,
                OffersReturnedAuthorisationManageViewLevel          = appUserSettings.OffersReturnedAuthorisationManageViewLevel,
                OrdersManageViewInternalSelectionLevel              = appUserSettings.OrdersManageViewInternalSelectionLevel,
                OrdersDespatchedAuthorisationManageViewLevel        = appUserSettings.OrdersDespatchedAuthorisationManageViewLevel,
                OrdersDeliveredAuthorisationManageViewLevel         = appUserSettings.OrdersDeliveredAuthorisationManageViewLevel,
                OrdersCollectedAuthorisationManageViewLevel         = appUserSettings.OrdersCollectedAuthorisationManageViewLevel,
                OrdersClosedAuthorisationManageViewLevel            = appUserSettings.OrdersClosedAuthorisationManageViewLevel,
                CampaignGeneralInfoExternalSelectionLevel           = appUserSettings.CampaignGeneralInfoExternalSelectionLevel,
                RequiredListingGeneralInfoExternalSelectionLevel    = appUserSettings.RequiredListingGeneralInfoExternalSelectionLevel,
                AvailableListingGeneralInfoExternalSelectionLevel   = appUserSettings.AvailableListingGeneralInfoExternalSelectionLevel,
                GroupListViewsForUserOnly                           = GroupViewHelpers.GetGroupEditViewForForUserOnly(db, appUserDetails.AppUserId),
                UserFriendListView                                  = FriendViewHelpers.GetFriendViewByType(db, appUserDetails.AppUserId, LevelEnum.User),
                UserBranchFriendListView                            = FriendViewHelpers.GetFriendViewByType(db, appUserDetails.AppUserId, LevelEnum.Branch),
                UserCompanyFriendListView                           = FriendViewHelpers.GetFriendViewByType(db, appUserDetails.AppUserId, LevelEnum.Company),
                UserBlockListView                                   = BlockViewHelpers.GetBlockViewByType(db, appUserDetails.AppUserId, LevelEnum.User),
                UserBranchBlockListView                             = BlockViewHelpers.GetBlockViewByType(db, appUserDetails.AppUserId, LevelEnum.Branch),
                UserCompanyBlockListView                            = BlockViewHelpers.GetBlockViewByType(db, appUserDetails.AppUserId, LevelEnum.Company)
            };

            return(view);
        }
Exemple #8
0
        public static AppUser UpdateAppUserFromAppUserEditView(ApplicationDbContext db, AppUserEditView view)
        {
            //Update AppUser
            AppUser appUser = GetAppUser(db, view.AppUserId);

            appUser.FirstName    = view.FirstName;
            appUser.LastName     = view.LastName;
            appUser.EntityStatus = view.EntityStatus;
            appUser.PrivacyLevel = view.PrivacyLevel;

            if (view.SelectedBranchId != null)
            {
                appUser.CurrentBranchId = view.SelectedBranchId.Value;
            }
            db.Entry(appUser).State = EntityState.Modified;
            db.SaveChanges();

            //Update BranchUser (Role)
            BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, appUser.AppUserId, appUser.CurrentBranchId);

            BranchUserHelpers.UpdateBranchUserRole(db, branchUser.BranchUserId, view.UserRole);

            //Update UserSettings
            AppUserSettingsHelpers.UpdateUserSettingsFromAppUserEditView(db, view);

            return(appUser);
        }
Exemple #9
0
        public static AppUserSettings UpdateUserSettingsFromAppUserEditView(ApplicationDbContext db, AppUserEditView view)
        {
            AppUserSettings settings = AppUserSettingsHelpers.GetAppUserSettings(db, view.AppUserSettingsId);

            settings.CampaignDashboardMaxDistance                        = view.CampaignDashboardMaxDistance;
            settings.CampaignDashboardMaxAge                             = view.CampaignDashboardMaxAge;
            settings.RequiredListingDashboardMaxDistance                 = view.RequiredListingDashboardMaxDistance;
            settings.RequiredListingDashboardMaxAge                      = view.RequiredListingDashboardMaxAge;
            settings.AvailableListingDashboardMaxDistance                = view.AvailableListingDashboardMaxDistance;
            settings.AvailableListingDashboardMaxAge                     = view.AvailableListingDashboardMaxAge;
            settings.CampaignDashboardExternalSelectionLevel             = view.CampaignDashboardExternalSelectionLevel;
            settings.RequiredListingDashboardExternalSelectionLevel      = view.RequiredListingDashboardExternalSelectionLevel;
            settings.AvailableListingDashboardExternalSelectionLevel     = view.AvailableListingDashboardExternalSelectionLevel;
            settings.CampaignGeneralInfoDisplayMyUserListings            = view.CampaignGeneralInfoDisplayMyUserListings;
            settings.CampaignGeneralInfoDisplayMyBranchListings          = view.CampaignGeneralInfoDisplayMyBranchListings;
            settings.CampaignGeneralInfoDisplayMyCompanyListings         = view.CampaignGeneralInfoDisplayMyCompanyListings;
            settings.CampaignGeneralInfoDisplayBlockedListings           = view.CampaignGeneralInfoDisplayBlockedListings;
            settings.CampaignGeneralInfoMaxDistance                      = view.CampaignGeneralInfoMaxDistance;
            settings.RequiredListingGeneralInfoDisplayMyUserListings     = view.RequiredListingGeneralInfoDisplayMyUserListings;
            settings.RequiredListingGeneralInfoDisplayMyBranchListings   = view.RequiredListingGeneralInfoDisplayMyBranchListings;
            settings.RequiredListingGeneralInfoDisplayMyCompanyListings  = view.RequiredListingGeneralInfoDisplayMyCompanyListings;
            settings.RequiredListingGeneralInfoDisplayBlockedListings    = view.RequiredListingGeneralInfoDisplayBlockedListings;
            settings.RequiredListingGeneralInfoMaxDistance               = view.RequiredListingGeneralInfoMaxDistance;
            settings.AvailableListingGeneralInfoDisplayMyUserListings    = view.AvailableListingGeneralInfoDisplayMyUserListings;
            settings.AvailableListingGeneralInfoDisplayMyBranchListings  = view.AvailableListingGeneralInfoDisplayMyBranchListings;
            settings.AvailableListingGeneralInfoDisplayMyCompanyListings = view.AvailableListingGeneralInfoDisplayMyCompanyListings;
            settings.AvailableListingGeneralInfoDisplayBlockedListings   = view.AvailableListingGeneralInfoDisplayBlockedListings;
            settings.AvailableListingGeneralInfoMaxDistance              = view.AvailableListingGeneralInfoMaxDistance;
            settings.CampaignManageViewInternalSelectionLevel            = view.CampaignManageViewInternalSelectionLevel;
            settings.RequiredListingManageViewInternalSelectionLevel     = view.RequiredListingManageViewInternalSelectionLevel;
            settings.AvailableListingManageViewInternalSelectionLevel    = view.AvailableListingManageViewInternalSelectionLevel;
            settings.OffersManageViewInternalSelectionLevel              = view.OffersManageViewInternalSelectionLevel;
            settings.OffersAcceptedAuthorisationManageViewLevel          = view.OffersAcceptedAuthorisationManageViewLevel;
            settings.OffersRejectedAuthorisationManageViewLevel          = view.OffersRejectedAuthorisationManageViewLevel;
            settings.OffersReturnedAuthorisationManageViewLevel          = view.OffersReturnedAuthorisationManageViewLevel;
            settings.OrdersManageViewInternalSelectionLevel              = view.OrdersManageViewInternalSelectionLevel;
            settings.OrdersDespatchedAuthorisationManageViewLevel        = view.OrdersDespatchedAuthorisationManageViewLevel;
            settings.OrdersDeliveredAuthorisationManageViewLevel         = view.OrdersDeliveredAuthorisationManageViewLevel;
            settings.OrdersReceivedAuthorisationManageViewLevel          = view.OrdersReceivedAuthorisationManageViewLevel;
            settings.OrdersCollectedAuthorisationManageViewLevel         = view.OrdersCollectedAuthorisationManageViewLevel;
            settings.OrdersClosedAuthorisationManageViewLevel            = view.OrdersClosedAuthorisationManageViewLevel;
            settings.CampaignGeneralInfoExternalSelectionLevel           = view.CampaignGeneralInfoExternalSelectionLevel;
            settings.RequiredListingGeneralInfoExternalSelectionLevel    = view.RequiredListingGeneralInfoExternalSelectionLevel;
            settings.AvailableListingGeneralInfoExternalSelectionLevel   = view.AvailableListingGeneralInfoExternalSelectionLevel;

            db.Entry(settings).State = EntityState.Modified;
            db.SaveChanges();

            return(settings);
        }