Exemplo n.º 1
0
        public static void DeleteFavorites(long id)
        {
            using (var ctx = new RentooloEntities())
            {
                Favorites obj = ctx.Favorites.Single(x => x.Id == id);

                ctx.Favorites.Remove(obj);

                try
                {
                    ctx.SaveChanges();
                }
                catch (System.Exception ex)
                {
                    DataHelper.AddException(ex);
                }
            }
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            string eventName = string.Empty;
            string result    = string.Empty;
            string id        = string.Empty;
            string comment   = string.Empty;

            eventName = context.Request["e"];
            result    = context.Request["r"];
            id        = context.Request["id"];
            comment   = context.Request["c"];

            ///Add favorites
            if (eventName == "af")
            {
                string userName = context.User.Identity.Name;

                if (!string.IsNullOrEmpty(userName))
                {
                    Users user = DataHelper.GetUserByName(userName);

                    Rentoolo.Model.Favorites favorites = new Rentoolo.Model.Favorites
                    {
                        UserId   = user.UserId,
                        AdvertId = Convert.ToInt64(id)
                    };

                    FavoritesHelper.AddFavorites(favorites);
                }
                else
                {
                    var uid = context.Request.Cookies["uid"];

                    if (uid != null)
                    {
                        FavoritesByCookies favoritesByCookies = new FavoritesByCookies
                        {
                            UserCookiesId = uid.Value,
                            AdvertId      = Convert.ToInt64(id)
                        };

                        FavoritesHelper.AddFavoritesByCookies(favoritesByCookies);
                    }
                }
            }

            if (eventName == "saveUserParam")
            {
                if (id == "Referrer")
                {
                    Model.Users referal = DataHelper.GetUserByName(context.User.Identity.Name);

                    int publicId;

                    if (!int.TryParse(result, out publicId))
                    {
                        return;
                    }

                    Model.Users referer = DataHelper.GetUserByPublicId(publicId);

                    if (referer == null)
                    {
                        return;
                    }

                    //сделать проверку что не является рефералом реферера и на уровень выше тоже

                    if (referer.UserId == referal.UserId)
                    {
                        return;
                    }

                    Model.Referrals upperReferal = DataHelper.GetReferral(referer.UserId);

                    if (upperReferal != null && upperReferal.ReferrerUserId == referal.UserId)
                    {
                        return;
                    }

                    if (upperReferal != null)
                    {
                        Model.Referrals upper2Referal = DataHelper.GetReferral(upperReferal.ReferrerUserId);

                        if (upper2Referal != null && upper2Referal.ReferrerUserId == referal.UserId)
                        {
                            return;
                        }
                    }

                    Model.Referrals referralItem = new Model.Referrals
                    {
                        ReferralUserId = referal.UserId,
                        ReferrerUserId = referer.UserId,
                        WhenDate       = DateTime.Now
                    };

                    DataHelper.AddReferral(referralItem);
                }

                if (id == "Email")
                {
                    DataHelper.UpdateUserEmail(context.User.Identity.Name, result);
                }
                else
                {
                    DataHelper.UpdateUserParametr(context.User.Identity.Name, id, result);
                }
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write("Ok");
        }