ToUserProfileModel() публичный Метод

public ToUserProfileModel ( ProfileBase profileBase ) : UserProfileModel
profileBase System.Web.Profile.ProfileBase
Результат Spontaneous.WebApp.Models.UserProfileModel
Пример #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();
            }
        }
Пример #2
0
        public string GetUserProfile(string userName)
        {
            try
            {
                UserProfileModel userProfile = null;
                if (string.IsNullOrEmpty(userName))
                {
                    ViewBag.Massage = "User Name is null or empty";
                }
                else
                {
                    var userProfielBase = UserProfileFacade.GetUserProfile(userName);
                    if (UserProfileFacade.CheckIfJustCreatedProfile(userProfielBase))
                    {
                        ViewBag.Massage = "User not exist.";
                    }
                    else
                    {
                        var converter = new ToViewModel();
                        userProfile = converter.ToUserProfileModel(userProfielBase);
                    }

                    if (userProfile.InsulinCalcProfile == null)
                    {
                        UserBaseInsulinCalcProfileModel userInsulineProfile = new PumpInsulinProfileModel();
                        //{
                        //    BirthDate = DateTime.UtcNow,
                        //    MinSugarRange = 110,
                        //    MaxSugarRange = 130,
                        //    Sex = Sex.Male,
                        //    UnitReductionValue = 1.2,
                        //    InsulinCarbohydrateRatio = 2,
                        //    Weight = 90
                        //};

                        //UserBaseInsulinCalcProfileModel userInsulineProfile = new RapidInsulinProfileModel()
                        //{
                        //    BirthDate = DateTime.Parse("25/05/1984"),
                        //    MinSugarRange = 110,
                        //    MaxSugarRange = 130,
                        //    Sex = Sex.Male,
                        //    UnitReductionValue = 1.2,
                        //    InsulinCarbohydrateRatio = 2,
                        //    Weight = 90,
                        //    BasalInsulinAmount = 3.4
                        //};
                        userProfile.InsulinCalcProfile = userInsulineProfile;
                    }
                }
                //var jsonResult = Json(userProfile, JsonRequestBehavior.AllowGet);
                //return jsonResult;
                var jsonResult = JsonConvert.SerializeObject(userProfile, Formatting.Indented, new StringEnumConverter());
                return jsonResult;
            }
            catch (Exception ex)
            {
                log.ErrorFormat("[GetUserProfile] exception={0}.", ex);
                //return Json(null, JsonRequestBehavior.AllowGet);
                return null;
                //throw;
            }
        }