Spontaneous.WebApp.Services.ModelConverter.ToViewModel.ToUserProfileModel C# (CSharp) Method

ToUserProfileModel() public method

public ToUserProfileModel ( ProfileBase profileBase ) : UserProfileModel
profileBase System.Web.Profile.ProfileBase
return Spontaneous.WebApp.Models.UserProfileModel
        public UserProfileModel ToUserProfileModel(ProfileBase profileBase)
        {
            UserProfileModel userProf = null;
            if (profileBase != null)
            {
                userProf = new UserProfileModel()
                {
                    UserName = profileBase.UserName,
                    UserType = profileBase.GetUserType()
                };
                if (!string.IsNullOrEmpty(userProf.UserName))
                {
                    var userRoles = Roles.GetRolesForUser(userProf.UserName);
                    userProf.UserRole = userRoles != null && userRoles.Length > 0 ? userRoles[0] : "";
                }
                var userData = profileBase.GetUserData();
                if (userData != null && userData.BaseInsulinCalcProfile != null)
                {
                    userProf.InsulinCalcProfile = ToUserBaseInsulinCalcProfileModel(userData.BaseInsulinCalcProfile);
                }
            }
            return userProf;
        }

Usage Example

Ejemplo n.º 1
0
        //
        // GET: /User/Create
        public ActionResult Edit(string userName)
        {
            try
            {
                UserProfileModel userProfile = null;
                if (string.IsNullOrEmpty(userName))
                {
                    ViewBag.Massage = "User Name is null or empty";
                    return RedirectToAction("FindUserData");
                }
                else
                {
                    var userProfielBase = UserProfileFacade.GetUserProfile(userName);
                    if (UserProfileFacade.CheckIfJustCreatedProfile(userProfielBase))
                    {
                        ViewBag.Massage = "User not exist.";
                        return RedirectToAction("FindUserData", new { userName = userName });
                    }
                    else
                    {
                        var converter = new ToViewModel();
                        userProfile = converter.ToUserProfileModel(userProfielBase);
                    }

                    if (userProfile.InsulinCalcProfile == null)
                    {
                        UserBaseInsulinCalcProfileModel userInsulineProfile = new PumpInsulinProfileModel();
                        userProfile.InsulinCalcProfile = userInsulineProfile;
                    }
                }

                ViewData["reductionUnits"] = DropDownListForHelper.GetSelectListForEnumType<UnitReductionUnits>();
                ViewData["dosageUnits"] = DropDownListForHelper.GetSelectListForEnumType<DosageUnits>();
                ViewData["pumps"] = DropDownListForHelper.GetSelectListForEnumType<PumpType>();
                ViewData["sexes"] = DropDownListForHelper.GetSelectListForEnumType<Sex>();

                return View(userProfile);
            }
            catch (Exception e)
            {
                log.ErrorFormat("[Edit] Error: Exception={0}.", e.Message);
                return View();
            }
        }
All Usage Examples Of Spontaneous.WebApp.Services.ModelConverter.ToViewModel::ToUserProfileModel