Пример #1
0
        public Checkout ShowCheckout()
        {
            HttpCookie cookieReq = HttpContext.Current.Request.Cookies[cookieName];

            if (cookieReq != null)
            {
                #region Получение корзины из куки
                string data = cookieReq[cart];

                var temp = data.Split('|').ToList();

                Dictionary <int, int> cookieData = new Dictionary <int, int>();

                foreach (var t in temp)
                {
                    cookieData.Add(Convert.ToInt32(t.Split(',')[0]), Convert.ToInt32(t.Split(',')[1]));
                }

                foreach (var tempData in cookieData)
                {
                    totalPrice += _db.ItemsDB.Find(tempData.Key).Price *tempData.Value;
                }
                #endregion
            }

            Int32 unixTimeStamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

            var random = r.Next(1, 9999);

            LiqPayId = (unixTimeStamp + random).ToString();

            string orderId = LiqPayId;

            //LiqPayId = Hash.EncryptStringAES(LiqPayId.ToString(), sharedKey);

            Checkout checkout = new Checkout();
            checkout.totalAmount = totalPrice;

            if (HttpContext.Current.Request.Cookies["lang"].Value == "en")
            {
                var json = new WebClient().DownloadString(PrivatBankData.getUrl());

                dynamic stuff = JsonConvert.DeserializeObject <List <PrivatBankData> >(json).ToList();

                double sale = Convert.ToDouble(stuff[1].sale);

                checkout.totalAmount = Math.Round(totalPrice / sale, 2);
            }

            checkout.PaymentData = LiqPayData(orderId);
            checkout.LiqPayId    = LiqPayId;

            return(checkout);
        }
Пример #2
0
        public double TotalPrice()
        {
            const string cart       = "Cart";
            const string cookieName = "CartCookie";//имя куки

            DatabaseContext _db = new DatabaseContext();

            HttpCookie cookieReq = HttpContext.Current.Request.Cookies[cookieName];

            double totalPrice = 0;

            if (cookieReq != null)
            {
                #region Получение корзины из куки
                string data = cookieReq[cart];

                var temp = data.Split('|').ToList();

                Dictionary <int, int> cookieData = new Dictionary <int, int>();

                foreach (var t in temp)
                {
                    cookieData.Add(Convert.ToInt32(t.Split(',')[0]), Convert.ToInt32(t.Split(',')[1]));
                }

                foreach (var tempData in cookieData)
                {
                    totalPrice += _db.ItemsDB.Find(tempData.Key).Price *tempData.Value;
                }
                #endregion
            }

            if (HttpContext.Current.Request.Cookies["lang"].Value == "en")
            {
                var json = new WebClient().DownloadString(PrivatBankData.getUrl());

                dynamic stuff = JsonConvert.DeserializeObject <List <PrivatBankData> >(json).ToList();

                double sale = Convert.ToDouble(stuff[1].sale);

                totalPrice = Math.Round(totalPrice / sale, 2);
            }

            return(totalPrice);
        }
Пример #3
0
        public List <DbItems> GetItems()
        {
            var json = new WebClient().DownloadString(PrivatBankData.getUrl());

            dynamic stuff = JsonConvert.DeserializeObject <List <PrivatBankData> >(json).ToList();

            double sale = stuff[1].sale;

            var data =
                (from entry in _db.ItemsDB
                 select entry).ToList();

            foreach (var item in data)
            {
                item.Price = item.Price / sale;
            }

            return(data);
        }
Пример #4
0
        public Item GetItemById(int id)
        {
            var language = Cookie.CheckLanguageCookie();

            Item data;

            switch (language)
            {
            case "uk":
                var dataUA =
                    (from temp in _db.ItemsDB
                     where temp.Id == id
                     select new Item
                {
                    Id = temp.Id,
                    Category = temp.CategoryUA,
                    Name = temp.NameUA,
                    Image = temp.Image,
                    Image2 = temp.Image2,
                    Image3 = temp.Image3,
                    Image4 = temp.Image4,
                    Price = temp.Price,
                    Description = temp.DescriptionUA
                }).First();

                data = dataUA;

                break;

            case "en":

                var json = new WebClient().DownloadString(PrivatBankData.getUrl());

                dynamic stuff = JsonConvert.DeserializeObject <List <PrivatBankData> >(json).ToList();

                double sale = Convert.ToDouble(stuff[1].sale);

                var dataEN =
                    (from temp in _db.ItemsDB
                     where temp.Id == id
                     select new Item
                {
                    Id = temp.Id,
                    Category = temp.CategoryEN,
                    Name = temp.NameEN,
                    Image = temp.Image,
                    Image2 = temp.Image2,
                    Image3 = temp.Image3,
                    Image4 = temp.Image4,
                    Price = Math.Round(temp.Price / sale, 2),
                    Description = temp.DescriptionEN
                }).First();

                data = dataEN;

                break;

            default:
                var dataRU =
                    (from temp in _db.ItemsDB
                     where temp.Id == id
                     select new Item
                {
                    Id = temp.Id,
                    Category = temp.CategoryRU,
                    Name = temp.NameRU,
                    Image = temp.Image,
                    Image2 = temp.Image2,
                    Image3 = temp.Image3,
                    Image4 = temp.Image4,
                    Price = temp.Price,
                    Description = temp.DescriptionRU
                }).First();

                data = dataRU;

                break;
            }

            return(data);
        }
Пример #5
0
        public List <Item> GetSameItems(string categoryName)
        {
            var language = Cookie.CheckLanguageCookie();

            List <Item> data = new List <Item>();

            switch (language)
            {
            case "uk":
                var dataUA =
                    (from temp in _db.ItemsDB
                     where temp.CategoryUA == categoryName
                     select new Item
                {
                    Id = temp.Id,
                    Category = temp.CategoryUA,
                    Name = temp.NameUA,
                    Image = temp.Image,
                    Price = temp.Price,
                    Description = temp.DescriptionUA
                }).ToList();

                data = dataUA;

                break;

            case "en":
                var json = new WebClient().DownloadString(PrivatBankData.getUrl());

                dynamic stuff = JsonConvert.DeserializeObject <List <PrivatBankData> >(json).ToList();

                double sale = Convert.ToDouble(stuff[1].sale);

                var dataEN =
                    (from temp in _db.ItemsDB
                     where temp.CategoryEN == categoryName
                     select new Item
                {
                    Id = temp.Id,
                    Category = temp.CategoryEN,
                    Name = temp.NameEN,
                    Image = temp.Image,
                    Price = Math.Round(temp.Price / sale, 2),
                    Description = temp.DescriptionEN
                }).ToList();

                data = dataEN;

                break;

            default:
                var dataRU =
                    (from temp in _db.ItemsDB
                     where temp.CategoryRU == categoryName
                     select new Item
                {
                    Id = temp.Id,
                    Category = temp.CategoryRU,
                    Name = temp.NameRU,
                    Image = temp.Image,
                    Price = temp.Price,
                    Description = temp.DescriptionRU
                }).ToList();

                data = dataRU;

                break;
            }

            List <Item> sameItems = new List <Item>();

            Random r = new Random();

            while (sameItems.Count < 5)
            {
                var number = r.Next(data.Count());

                if (!sameItems.Contains(data[number]))
                {
                    sameItems.Add(data[number]);
                }

                if (sameItems.Count == data.Count)
                {
                    break;
                }
            }

            return(sameItems);
        }
Пример #6
0
        public static List <Cart> getCartList()
        {
            const string cart       = "Cart";
            const string cookieName = "CartCookie";//имя куки

            HttpCookie cookieReq = HttpContext.Current.Request.Cookies[cookieName];

            DatabaseContext _db = new DatabaseContext();

            List <Cart> cartList = new List <Cart>();

            if (cookieReq != null)
            {
                #region Получение корзины из куки
                string data = cookieReq[cart];

                var temp = data.Split('|').ToList();

                Dictionary <int, int> cookieData = new Dictionary <int, int>();

                foreach (var t in temp)
                {
                    cookieData.Add(Convert.ToInt32(t.Split(',')[0]), Convert.ToInt32(t.Split(',')[1]));
                }

                var language = Cookie.CheckLanguageCookie();

                switch (language)
                {
                case "uk":

                    foreach (var tempData in cookieData)
                    {
                        var itemData =
                            (from entry in _db.ItemsDB
                             where entry.Id == tempData.Key
                             select new Item
                        {
                            Id = entry.Id,
                            Category = entry.CategoryUA,
                            Name = entry.NameUA,
                            Image = entry.Image,
                            Price = entry.Price,
                            Description = entry.DescriptionUA
                        }).First();

                        cartList.Add(
                            new Cart(
                                itemData,
                                tempData.Value,
                                _db.ItemsDB.Find(tempData.Key).Price *tempData.Value
                                ));
                    }
                    break;

                case "en":
                    var json = new WebClient().DownloadString(PrivatBankData.getUrl());

                    dynamic stuff = JsonConvert.DeserializeObject <List <PrivatBankData> >(json).ToList();

                    double sale = Convert.ToDouble(stuff[1].sale);

                    foreach (var tempData in cookieData)
                    {
                        var itemData =
                            (from entry in _db.ItemsDB
                             where entry.Id == tempData.Key
                             select new Item
                        {
                            Id = entry.Id,
                            Category = entry.CategoryEN,
                            Name = entry.NameEN,
                            Image = entry.Image,
                            Price = Math.Round(entry.Price / sale, 2),
                            Description = entry.DescriptionEN
                        }).First();

                        cartList.Add(
                            new Cart(
                                itemData,
                                tempData.Value,
                                Math.Round(_db.ItemsDB.Find(tempData.Key).Price / sale * tempData.Value, 2)
                                ));
                    }
                    break;

                default:
                    foreach (var tempData in cookieData)
                    {
                        var itemData =
                            (from entry in _db.ItemsDB
                             where entry.Id == tempData.Key
                             select new Item
                        {
                            Id = entry.Id,
                            Category = entry.CategoryRU,
                            Name = entry.NameRU,
                            Image = entry.Image,
                            Price = entry.Price,
                            Description = entry.DescriptionRU
                        }).First();

                        cartList.Add(
                            new Cart(
                                itemData,
                                tempData.Value,
                                _db.ItemsDB.Find(tempData.Key).Price *tempData.Value
                                ));
                    }
                    break;
                }
                #endregion
            }

            return(cartList);
        }
Пример #7
0
        public List <Item> GetItems(string categoryName)
        {
            var language = Cookie.CheckLanguageCookie();

            List <Item> data = new List <Item>();

            switch (language)
            {
            case "uk":
                var dataUA =
                    (from entry in _db.ItemsDB
                     where entry.CategoryUA == categoryName
                     orderby entry.Id descending
                     select new Item
                {
                    Id = entry.Id,
                    Category = entry.CategoryUA,
                    Name = entry.NameUA,
                    Image = entry.Image,
                    Price = entry.Price,
                    Description = entry.DescriptionUA
                }).ToList();
                data = dataUA;
                break;

            case "en":
                var json = new WebClient().DownloadString(PrivatBankData.getUrl());

                dynamic stuff = JsonConvert.DeserializeObject <List <PrivatBankData> >(json).ToList();

                double sale = Convert.ToDouble(stuff[1].sale);

                var dataEN =
                    (from entry in _db.ItemsDB
                     where entry.CategoryEN == categoryName
                     orderby entry.Id descending
                     select new Item
                {
                    Id = entry.Id,
                    Category = entry.CategoryEN,
                    Name = entry.NameEN,
                    Image = entry.Image,
                    Price = Math.Round(entry.Price / sale, 2),
                    Description = entry.DescriptionEN
                }).ToList();
                data = dataEN;
                break;

            default:
                var dataRU =
                    (from entry in _db.ItemsDB
                     where entry.CategoryRU == categoryName
                     orderby entry.Id descending
                     select new Item
                {
                    Id = entry.Id,
                    Category = entry.CategoryRU,
                    Name = entry.NameRU,
                    Image = entry.Image,
                    Price = entry.Price,
                    Description = entry.DescriptionRU
                }).ToList();
                data = dataRU;
                break;
            }
            return(data);
        }