Esempio n. 1
0
        //1.topAreaCode应该取DIContainer.Resolve<IAreaSettingsManager>().Get().RootAreaCode,不应该公开出来;
        //2.parentAreaCode参数没必要加;
        //3.callback、selectTop没加注释,不知道什么意思;
        /// <summary>
        /// 输出地区选择器
        /// </summary>
        public static MvcHtmlString AreaSelector(this HtmlHelper htmlHelper, string id, string topAreaCode = "", string parentAreaCode = "", string currentAreaCode = "", int depth = 4, string callback = null, bool selectTop = true)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("参数名称id不能为空", "id");
            }
            htmlHelper.ViewData["id"]              = id;
            htmlHelper.ViewData["topAreaCode"]     = topAreaCode;
            htmlHelper.ViewData["parentAreaCode"]  = parentAreaCode;
            htmlHelper.ViewData["currentAreaCode"] = currentAreaCode;
            htmlHelper.ViewData["depth"]           = depth;
            htmlHelper.ViewData["callback"]        = callback;
            htmlHelper.ViewData["selectTop"]       = selectTop;

            htmlHelper.ViewData["login"]                  = "******";
            htmlHelper.ViewData["registerAreaCode"]       = "AreaCode";
            htmlHelper.ViewData["registerAreaName"]       = "AreaName";
            htmlHelper.ViewData["registerParentAreaCode"] = "ParentAreaCode";
            htmlHelper.ViewData["registerParentAreaName"] = "ParentAreaName";

            // 获取当前用户的注册地
            AreaService        areaService        = DIContainer.Resolve <AreaService>();
            UserProfileService userProfileService = new UserProfileService();
            IUser currentUser = UserContext.CurrentUser; //获取当前登录用户

            if (currentUser == null)
            {
                return(htmlHelper.DisplayForModel("AreaSelector"));
            }
            UserProfile userProfile = userProfileService.Get(currentUser.UserId);

            if (userProfile == null || string.IsNullOrEmpty(userProfile.NowAreaCode))
            {
                return(htmlHelper.DisplayForModel("AreaSelector"));
            }

            Area area = areaService.Get(userProfile.NowAreaCode);

            htmlHelper.ViewData["login"]                  = "******";
            htmlHelper.ViewData["registerAreaCode"]       = userProfile.NowAreaCode;
            htmlHelper.ViewData["registerAreaName"]       = area.Name;
            htmlHelper.ViewData["registerParentAreaCode"] = area.ParentCode;
            string parentAreaName = areaService.Get(area.ParentCode).Name;

            htmlHelper.ViewData["registerParentAreaName"] = parentAreaName;


            return(htmlHelper.DisplayForModel("AreaSelector"));
        }
        //1.topAreaCode应该取DIContainer.Resolve<IAreaSettingsManager>().Get().RootAreaCode,不应该公开出来;
        //2.parentAreaCode参数没必要加;
        //3.callback、selectTop没加注释,不知道什么意思;
        /// <summary>
        /// 输出地区选择器
        /// </summary> 
        public static MvcHtmlString AreaSelector(this HtmlHelper htmlHelper, string id, string topAreaCode = "", string parentAreaCode = "", string currentAreaCode = "", int depth = 4, string callback = null, bool selectTop = true)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("参数名称id不能为空", "id");
            }
            htmlHelper.ViewData["id"] = id;
            htmlHelper.ViewData["topAreaCode"] = topAreaCode;
            htmlHelper.ViewData["parentAreaCode"] = parentAreaCode;
            htmlHelper.ViewData["currentAreaCode"] = currentAreaCode;
            htmlHelper.ViewData["depth"] = depth;
            htmlHelper.ViewData["callback"] = callback;
            htmlHelper.ViewData["selectTop"] = selectTop;

            htmlHelper.ViewData["login"] = "******";
            htmlHelper.ViewData["registerAreaCode"] = "AreaCode";
            htmlHelper.ViewData["registerAreaName"] = "AreaName";
            htmlHelper.ViewData["registerParentAreaCode"] = "ParentAreaCode";
            htmlHelper.ViewData["registerParentAreaName"] = "ParentAreaName";

            // 获取当前用户的注册地
            AreaService areaService = DIContainer.Resolve<AreaService>();
            UserProfileService userProfileService = new UserProfileService();
            IUser currentUser = UserContext.CurrentUser; //获取当前登录用户

            if (currentUser == null)
            {
                return htmlHelper.DisplayForModel("AreaSelector");
            }
            UserProfile userProfile = userProfileService.Get(currentUser.UserId);
            if (userProfile == null || string.IsNullOrEmpty(userProfile.NowAreaCode))
            {
                return htmlHelper.DisplayForModel("AreaSelector");
            }

            Area area = areaService.Get(userProfile.NowAreaCode);
            htmlHelper.ViewData["login"] = "******";
            htmlHelper.ViewData["registerAreaCode"] = userProfile.NowAreaCode;
            htmlHelper.ViewData["registerAreaName"] = area.Name;
            htmlHelper.ViewData["registerParentAreaCode"] = area.ParentCode;
            string parentAreaName = areaService.Get(area.ParentCode).Name;
            htmlHelper.ViewData["registerParentAreaName"] = parentAreaName;

            return htmlHelper.DisplayForModel("AreaSelector");
        }
Esempio n. 3
0
        /// <summary>
        /// 转换为UserProfile用于数据库存储
        /// </summary>
        public UserProfile AsUserProfile(long userId)
        {
            UserProfile userProfile;
            if (UserId > 0)
            {
                UserProfileService userProfileService = new UserProfileService();
                userProfile = userProfileService.Get(UserId);
                userProfile.BirthdayType = this.BirthdayType;

                if (this.Gender == GenderType.FeMale)
                    userProfile.Gender = GenderType.FeMale;
                else if (this.Gender == GenderType.Male)
                    userProfile.Gender = GenderType.Male;

                else
                    userProfile.Gender = 0;

                if (this.BirthdayType == BirthdayType.LunarBirthday)
                {
                    ChinaDateTime cdt = new ChinaDateTime(LunarYear, LunarMonth, LunarDay);
                    userProfile.LunarBirthday = new DateTime(LunarYear, LunarMonth, LunarDay);
                    userProfile.Birthday = cdt.ToDateTime();

                }
                else
                {
                    if (Birthday != null)
                    {
                        ChinaDateTime cdt = new ChinaDateTime(Birthday.Value);
                        userProfile.Birthday = Birthday.Value;
                        userProfile.LunarBirthday = new DateTime(cdt.Year, cdt.Month, cdt.DayOfMonth);
                    }
                }

                if (!string.IsNullOrEmpty(Introduction))
                    userProfile.Introduction = this.Introduction;
                else
                    userProfile.Introduction = "";

                if (!string.IsNullOrEmpty(Email))
                    userProfile.Email = this.Email;
                else
                    userProfile.Email = "";

                if (!string.IsNullOrEmpty(Mobile))
                    userProfile.Mobile = this.Mobile;
                else
                    userProfile.Mobile = "";

                if (!string.IsNullOrEmpty(Msn))
                    userProfile.Msn = this.Msn;
                else
                    userProfile.Msn = "";

                if (!string.IsNullOrEmpty(NowAreaCode))
                    userProfile.NowAreaCode = this.NowAreaCode;
                else
                    userProfile.NowAreaCode = "";

                if (!string.IsNullOrEmpty(HomeAreaCode))
                    userProfile.HomeAreaCode = this.HomeAreaCode;
                else
                    userProfile.HomeAreaCode = "";

                if (!string.IsNullOrEmpty(QQ))
                    userProfile.QQ = this.QQ;
                else
                    userProfile.QQ = "";
            }
            else
            {
                userProfile = UserProfile.New();

                userProfile.BirthdayType = this.BirthdayType;

                if (this.Gender == GenderType.FeMale)
                    userProfile.Gender = GenderType.FeMale;
                else if (this.Gender == GenderType.Male)
                    userProfile.Gender = GenderType.FeMale;
                else
                    userProfile.Gender = 0;

                if (!string.IsNullOrEmpty(HomeAreaCode))
                    userProfile.HomeAreaCode = this.HomeAreaCode;
                else
                    userProfile.HomeAreaCode = "";

                if (!string.IsNullOrEmpty(NowAreaCode))
                    userProfile.NowAreaCode = this.NowAreaCode;
                else
                    userProfile.NowAreaCode = "";

                if (!string.IsNullOrEmpty(Email))
                    userProfile.Email = this.Email;
                else
                    userProfile.Email = "";

                if (!string.IsNullOrEmpty(Introduction))
                    userProfile.Introduction = this.Introduction;
                else
                    userProfile.Introduction = "";

                if (!string.IsNullOrEmpty(Mobile))
                    userProfile.Mobile = this.Mobile;
                else
                    userProfile.Mobile = "";

                if (!string.IsNullOrEmpty(Msn))
                    userProfile.Msn = this.Msn;
                else
                    userProfile.Msn = "";

                if (!string.IsNullOrEmpty(QQ))
                    userProfile.QQ = this.QQ;
                else
                    userProfile.QQ = "";

                if (Birthday != null)
                {
                    if (this.BirthdayType == BirthdayType.LunarBirthday)
                    {
                        ChinaDateTime cdt = new ChinaDateTime(LunarYear, LunarMonth, LunarDay);
                        userProfile.LunarBirthday = new DateTime(LunarYear, LunarMonth, LunarDay);
                        userProfile.Birthday = cdt.ToDateTime();

                    }
                    else
                    {
                        ChinaDateTime cdt = new ChinaDateTime(Birthday.Value);
                        userProfile.Birthday = Birthday.Value;
                        userProfile.LunarBirthday = new DateTime(cdt.Year, cdt.Month, cdt.DayOfMonth);
                    }
                }
                else
                {
                    ChinaDateTime cdt = new ChinaDateTime(DateTime.UtcNow);
                    userProfile.Birthday = DateTime.UtcNow;
                    userProfile.LunarBirthday = new DateTime(cdt.Year, cdt.Month, cdt.DayOfMonth);
                }

                userProfile.UserId = userId;

            }
            return userProfile;
        }
Esempio n. 4
0
        /// <summary>
        /// 转换为UserProfile用于数据库存储
        /// </summary>
        public UserProfile AsUserProfile(long userId)
        {
            UserProfile userProfile;

            if (UserId > 0)
            {
                UserProfileService userProfileService = new UserProfileService();
                userProfile = userProfileService.Get(UserId);
                userProfile.BirthdayType = this.BirthdayType;

                if (this.Gender == GenderType.FeMale)
                {
                    userProfile.Gender = GenderType.FeMale;
                }
                else if (this.Gender == GenderType.Male)
                {
                    userProfile.Gender = GenderType.Male;
                }

                else
                {
                    userProfile.Gender = 0;
                }

                if (this.BirthdayType == BirthdayType.LunarBirthday)
                {
                    ChinaDateTime cdt = new ChinaDateTime(LunarYear, LunarMonth, LunarDay);
                    userProfile.LunarBirthday = new DateTime(LunarYear, LunarMonth, LunarDay);
                    userProfile.Birthday      = cdt.ToDateTime();
                }
                else
                {
                    if (Birthday != null)
                    {
                        ChinaDateTime cdt = new ChinaDateTime(Birthday.Value);
                        userProfile.Birthday      = Birthday.Value;
                        userProfile.LunarBirthday = new DateTime(cdt.Year, cdt.Month, cdt.DayOfMonth);
                    }
                }

                if (!string.IsNullOrEmpty(Introduction))
                {
                    userProfile.Introduction = this.Introduction;
                }
                else
                {
                    userProfile.Introduction = "";
                }

                if (!string.IsNullOrEmpty(Email))
                {
                    userProfile.Email = this.Email;
                }
                else
                {
                    userProfile.Email = "";
                }

                if (!string.IsNullOrEmpty(Mobile))
                {
                    userProfile.Mobile = this.Mobile;
                }
                else
                {
                    userProfile.Mobile = "";
                }

                if (!string.IsNullOrEmpty(Msn))
                {
                    userProfile.Msn = this.Msn;
                }
                else
                {
                    userProfile.Msn = "";
                }

                if (!string.IsNullOrEmpty(NowAreaCode))
                {
                    userProfile.NowAreaCode = this.NowAreaCode;
                }
                else
                {
                    userProfile.NowAreaCode = "";
                }

                if (!string.IsNullOrEmpty(HomeAreaCode))
                {
                    userProfile.HomeAreaCode = this.HomeAreaCode;
                }
                else
                {
                    userProfile.HomeAreaCode = "";
                }

                if (!string.IsNullOrEmpty(QQ))
                {
                    userProfile.QQ = this.QQ;
                }
                else
                {
                    userProfile.QQ = "";
                }
            }
            else
            {
                userProfile = UserProfile.New();

                userProfile.BirthdayType = this.BirthdayType;

                if (this.Gender == GenderType.FeMale)
                {
                    userProfile.Gender = GenderType.FeMale;
                }
                else if (this.Gender == GenderType.Male)
                {
                    userProfile.Gender = GenderType.FeMale;
                }
                else
                {
                    userProfile.Gender = 0;
                }

                if (!string.IsNullOrEmpty(HomeAreaCode))
                {
                    userProfile.HomeAreaCode = this.HomeAreaCode;
                }
                else
                {
                    userProfile.HomeAreaCode = "";
                }

                if (!string.IsNullOrEmpty(NowAreaCode))
                {
                    userProfile.NowAreaCode = this.NowAreaCode;
                }
                else
                {
                    userProfile.NowAreaCode = "";
                }

                if (!string.IsNullOrEmpty(Email))
                {
                    userProfile.Email = this.Email;
                }
                else
                {
                    userProfile.Email = "";
                }

                if (!string.IsNullOrEmpty(Introduction))
                {
                    userProfile.Introduction = this.Introduction;
                }
                else
                {
                    userProfile.Introduction = "";
                }

                if (!string.IsNullOrEmpty(Mobile))
                {
                    userProfile.Mobile = this.Mobile;
                }
                else
                {
                    userProfile.Mobile = "";
                }

                if (!string.IsNullOrEmpty(Msn))
                {
                    userProfile.Msn = this.Msn;
                }
                else
                {
                    userProfile.Msn = "";
                }

                if (!string.IsNullOrEmpty(QQ))
                {
                    userProfile.QQ = this.QQ;
                }
                else
                {
                    userProfile.QQ = "";
                }

                if (Birthday != null)
                {
                    if (this.BirthdayType == BirthdayType.LunarBirthday)
                    {
                        ChinaDateTime cdt = new ChinaDateTime(LunarYear, LunarMonth, LunarDay);
                        userProfile.LunarBirthday = new DateTime(LunarYear, LunarMonth, LunarDay);
                        userProfile.Birthday      = cdt.ToDateTime();
                    }
                    else
                    {
                        ChinaDateTime cdt = new ChinaDateTime(Birthday.Value);
                        userProfile.Birthday      = Birthday.Value;
                        userProfile.LunarBirthday = new DateTime(cdt.Year, cdt.Month, cdt.DayOfMonth);
                    }
                }
                else
                {
                    ChinaDateTime cdt = new ChinaDateTime(DateTime.UtcNow);
                    userProfile.Birthday      = DateTime.UtcNow;
                    userProfile.LunarBirthday = new DateTime(cdt.Year, cdt.Month, cdt.DayOfMonth);
                }

                userProfile.UserId = userId;
            }
            return(userProfile);
        }