コード例 #1
0
        private void PopulateProfileViewModel(ProfileViewModel objProfileViewModel)
        {
             ApplicationUser user = (ApplicationUser)Session["sesApplicationUser"];
             _profileDAL = new ProfileDAL();
            objProfileViewModel.USERNAME = user.UserName;
            objProfileViewModel.DATEOFBIRTH = user.DateOfBirth;

            if (user.CountryId > 0)
            { objProfileViewModel.COUNTRYNAME = _profileDAL.GetCountryByCountryId(user.CountryId).CountryName; }

            if (user.StateId > 0)
            { objProfileViewModel.STATENAME = _profileDAL.GetStateByStateId(user.StateId).StateName; }
            
            if (user.TimeZoneId > 0)
            { objProfileViewModel.TIMEZONENAME = _profileDAL.GetTimezoneByTimezoneId(user.TimeZoneId).TimeZoneName; }
            
            objProfileViewModel.TWITCHUSERID = user.TwitchId;
            objProfileViewModel.PSNID = user.PSNId;
            objProfileViewModel.XBOXID = user.XBoxId;
            objProfileViewModel.COUNTRYLIST = _profileDAL.GetAllCountries();
            objProfileViewModel.STATELIST = _profileDAL.GetAllStates();
            objProfileViewModel.TIMEZONELIST = _profileDAL.GetAllTimezones();

            objProfileViewModel.SELECTEDCOUNTRYID = user.CountryId;
            objProfileViewModel.SELECTEDSTATEID = user.StateId;
            objProfileViewModel.SELECTEDTIMEZONEID = user.TimeZoneId;
            objProfileViewModel.profilePhoto = new ProfilePhotoModel();
            objProfileViewModel.profilePhoto.PHOTOBINARY = user.ProfilePhoto;

            objProfileViewModel.AccountActivity = _profileDAL.GetAccountActivity(user.Id);
            
        }
コード例 #2
0
        public ActionResult Save(ProfileViewModel paramProfileViewModel)
        {
            if (ModelState.IsValid)
            { 
                ApplicationUser objuser = (ApplicationUser)Session["sesApplicationUser"];

                var user = UserManager.FindById(objuser.Id);
                user.UserName = paramProfileViewModel.USERNAME;
                user.CountryId =  paramProfileViewModel.SELECTEDCOUNTRYID == null ? 0 : (int)paramProfileViewModel.SELECTEDCOUNTRYID;
                user.StateId = paramProfileViewModel.SELECTEDSTATEID == null ? 0 : (int)paramProfileViewModel.SELECTEDSTATEID;
                user.TimeZoneId = paramProfileViewModel.SELECTEDTIMEZONEID == null ? 0 : (int)paramProfileViewModel.SELECTEDTIMEZONEID;

                user.DateOfBirth = paramProfileViewModel.DATEOFBIRTH;
                user.TwitchId = paramProfileViewModel.TWITCHUSERID;
                user.PSNId = paramProfileViewModel.PSNID;
                user.XBoxId = paramProfileViewModel.XBOXID;

                Session["sesApplicationUser"] = user;
                UserManager.Update(user);
                Success("User Profile has been updated successfully",true);
                PopulateProfileViewModel(paramProfileViewModel);
            }
            else
            {
                ViewBag.Edit = true;
                _profileDAL = new ProfileDAL();
                paramProfileViewModel.COUNTRYLIST = _profileDAL.GetAllCountries();

                paramProfileViewModel.STATELIST = _profileDAL.GetAllStates();
                paramProfileViewModel.TIMEZONELIST = _profileDAL.GetAllTimezones();
            }
            return View("userProfile", paramProfileViewModel);
        }