private void FillChildren(CMSPage cmsPage)
        {
            var childs = FullPageTable.Where(x => x.ParentID == cmsPage.ID).ToList();

            if (childs.Any())
            {
                _fullChildrenList.AddRange(childs.Select(x => x.ID));
            }
            foreach (var child in childs)
            {
                FillChildren(child);
            }
        }
        public HeaderViewModel()
        {
            var main = CMSPage.GetByType("MainPage").ToList();

            if (main.Any())
            {
                MainMenu = main.Concat(CMSPage.FullPageTable.Where(x => x.ViewMenu && x.Visible && !x.Deleted && x.ParentID == main.First().ID)
                                       .OrderBy(
                                           x => x.OrderNum).ToList()).ToList();
            }
            HeaderPhones = SiteSetting.Get <string>("HeaderPhone");
            FooterPhones = SiteSetting.Get <string>("FooterAdress");
        }
        private void FillChildrenList(CMSPage cmsPage, ref List <int> list, int count)
        {
            var childs = FullPageTable.Where(x => x.ParentID == cmsPage.ID).ToList();

            if (childs.Any())
            {
                list.AddRange(childs.Select(x => x.ID));
            }
            if (list.Count >= count)
            {
                return;
            }
            foreach (var child in childs)
            {
                FillChildrenList(child, ref list, count);
            }
        }
        public UploadingPointData ToUploadData()
        {
            var user  = Membership.GetUser();
            var myUID = user == null ? new Guid() : (Guid)user.ProviderUserKey;

            return(new UploadingPointData()
            {
                ID = ID,
                IsMyPoint = CreatorID == myUID || AccessHelper.IsMaster,
                IsRegion = MapCoords.Any(z => !z.IsMarker),
                PointPosition = MapCoords.First(z => z.IsMarker).ToCoordinate(),
                Description = Description,
                Name = Name,
                HeaderText =
                    Address + " / " +
                    (ObjectType == -1
                             ? " Зона «Не курят» / Курение запрещено"
                             : (ObjectType == 0
                                    ? " Зона «Спорная» / Курение разрешено"
                                    : " Зона «Курят» / Курение разрешено")),
                CommentsLink = CMSPage.Get("myobjects").FullUrl + "?oid=" + ID + "&uid=" + CreatorID,
                EditLink = CMSPage.Get("map").FullUrl + "#EditObj=" + ID,
                ImageLink =
                    MapObjectPhoto == null
                            ? ""
                            : UniversalEditorPagedData.GetImageWrapper("MapObjectPhotos", "ObjectID", ID.ToString(),
                                                                       "RawData"),
                IsMyFavorite = false,     //CreatorID == myUID,
                Address = Address,
                TypeID = TypeID,
                CommentCount = MapObjectComments.Count,
                SmokingType = ObjectType,
                RegionPosition =
                    MapCoords.Where(z => !z.IsMarker)
                    .OrderBy(x => x.OrderNum)
                    .ToList()
                    .Select(x => x.ToCoordinate())
                    .ToList(),
                IconNum = MapObjectType.Icon.Replace("icon-obj", ""),
                UserName = User.UserProfile.FullName,
                UserLink = User.UserProfile.EditProfilePage
            });
        }
        public static SocialAuthResult CheckAuth()
        {
            var from = HttpContext.Current.Request["from"];

            if (from.IsNullOrEmpty())
            {
                return(new SocialAuthResult());
            }

            var target = String.Format("http://ulogin.ru/token.php?token={0}&host={1}", HttpContext.Current.Request["token"],
                                       HttpContext.Current.Request.Url.Host);

            var wc = new WebClient();

            byte[] data = null;
            try
            {
                data = wc.DownloadData(target);
            }
            catch (Exception exxxx)
            {
                return(new SocialAuthResult()
                {
                    HasResult = true,
                    Message = "Ошибка при установлении соединения с сервером авторизации",
                    PageURL = "",
                    Popup = "Login"
                });
            }
            var js = Encoding.UTF8.GetString(data);

            js = DecodeEncodedNonAsciiCharacters(js);
            var serializer = new JavaScriptSerializer();
            var jsData     = serializer.Deserialize <UserDataFromNetwork>(js);

            if (string.IsNullOrEmpty(jsData.email))
            {
                return(new SocialAuthResult()
                {
                    HasResult = true,
                    Message = "Для регистрации через соцсеть, в соцсети должен быть указан email",
                    PageURL = "",
                    Popup = "Login"
                });
            }


            try
            {
                MembershipUser user  = null;
                var            exist = Membership.GetUserNameByEmail(jsData.email);
                if (!string.IsNullOrEmpty(exist))
                {
                    user = Membership.GetUser(exist);
                }

                //нет такого
                if (user == null)
                {
                    var pass = new Random(DateTime.Now.Millisecond).GeneratePassword(6);
                    //SiteExceptionLog.WriteToLog("Creating user = "******"Client");

                    var profile = new UserProfile()
                    {
                        UserID  = (Guid)user.ProviderUserKey,
                        FromIP  = HttpContext.Current.Request.GetRequestIP().ToIPInt(),
                        RegDate = DateTime.Now,
                        Email   = jsData.email,
                    };

                    profile.Name    = jsData.first_name ?? "";
                    profile.Surname = jsData.last_name ?? "";
                    profile.Nick    = jsData.nickname;
                    byte[] avatar;
                    try
                    {
                        avatar = wc.DownloadData(jsData.photo_big.IsNullOrEmpty() ? jsData.photo : jsData.photo_big);
                    }
                    catch
                    {
                        avatar = null;
                    }
                    profile.Avatar = avatar;

                    var db = new DB();
                    db.UserProfiles.InsertOnSubmit(profile);
                    db.SubmitChanges();


                    MailingList.Get("RegisterLetter")
                    .WithReplacement(
                        new MailReplacement("{PASSWORD}", pass)
                        ).To(jsData.email).Send();

                    FormsAuthentication.SetAuthCookie(jsData.email, true);
                }
                //есть чувак
                else
                {
                    //мыло подтверждено и совпало, логин совпал
                    if ((/*jsData.verified_email == 1 && */ jsData.email.ToLower() == user.Email.ToLower()))
                    {
                        FormsAuthentication.SetAuthCookie(user.UserName, true);
                    }
                    //редирект на страницу с формой, где выводим сообщение
                    else
                    {
                        return(new SocialAuthResult()
                        {
                            HasResult = true,
                            Message = (jsData.nickname == user.UserName
                                                  ? "Пользователь с таким логином уже зарегистрирован. Пожалуйста, укажите другой логин."
                                                  : "Пользователь с таким Email уже зарегистрирован. Пожалуйста укажите другой Email"),
                            PageURL = "",
                            Popup = "Login"    //?
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(new SocialAuthResult()
                {
                    HasResult = true,
                    Message = ex.Message,
                    PageURL = "",
                    Popup = "Login"
                });
            }
            return(new SocialAuthResult()
            {
                HasResult = true,
                Message = "",
                PageURL = CMSPage.Get(from).FullUrl
            });
        }