Esempio n. 1
0
        async void ClickDelete(object sender, EventArgs e)
        {
            if (!isError && !await OnePage.mainPage.DisplayMessageQuestion("Подтвердите действие", "Вы действительно хотите удалить этот товар?"))
            {
                return;
            }

            if (User.Singleton != null)
            {
                if (BasketItem.Quantity > 0)
                {
                    BasketItem.Quantity = -BasketItem.Quantity;
                }
                try {
                    await Basket.PushToBasketAsync(BasketItem);
                } catch (Exception) {
                    eventRefresh  = null;
                    eventRefresh += (obj, evn) => {
                        Button content = obj as Button;
                        content.IsEnabled = false;
                        ClickDelete(sender, e);
                    };
                    OnePage.redirectApp.basketView.Content = OnePage.mainPage.ShowMessageError(eventRefresh);
                    isError = true;
                    return;
                }
            }
            else
            {
                BasketDB basketDB;
                if (BasketItem.SizeValueId == null)
                {
                    basketDB = BasketDB.GetItemByID(BasketItem.ProductID);
                }
                else
                {
                    basketDB = BasketDB.GetItem(BasketItem.ProductID, BasketItem.SizeValueId ?? 0);
                }
                BasketDB.DeleteItem(basketDB.Id);
            }
            OnePage.redirectApp.RedirectToPage(PageName.Basket, true, true);

            if (isError)
            {
                OnePage.redirectApp.basketView.Content = OnePage.redirectApp.basketView.mainGrid;
            }
        }
Esempio n. 2
0
 async Task EditNotValidProduct()
 {
     foreach (var item in notValidBasketList)
     {
         if ((item.Quantity > item.ProductActualQuantity || !item.ProductAvailable) && !item.IsLocalBasket)
         {
             if (!item.ProductAvailable)
             {
                 item.Quantity = -item.Quantity;
             }
             else
             {
                 item.Quantity = item.ProductActualQuantity - item.Quantity;
             }
             await Basket.PushToBasketAsync(item);
         }
     }
 }
Esempio n. 3
0
        private async void OnStepperValueChanged(int value)
        {
            btnPlus.IsEnabled  = false;
            btnMinus.IsEnabled = false;

            if (!BasketItem.IsLocalBasket)                      // Товар в глобальной корзине
            {
                Basket basketToServer = new Basket {
                    Id          = BasketItem.Id,
                    ProductID   = BasketItem.ProductID,
                    SizeValueId = BasketItem.SizeValueId,
                    Quantity    = value,
                    Comment     = BasketItem.Comment
                };
                ContentAndHeads contentAndHeads;
                try {
                    contentAndHeads = await Basket.PushToBasketAsync(basketToServer);

                    isError = false;
                } catch (Exception) {
                    eventRefresh  = null;
                    eventRefresh += (sender, e) => {
                        Button content = sender as Button;
                        content.IsEnabled = false;
                        OnStepperValueChanged(value);
                    };
                    OnePage.redirectApp.basketView.Content = OnePage.mainPage.ShowMessageError(eventRefresh);
                    isError = true;
                    return;
                }
                if (contentAndHeads.requestStatus == System.Net.HttpStatusCode.OK)
                {
                    EditTotal(value);
                }
            }
            else                    // Товар в локальной корзине
            {
                BasketDB basketDB = new BasketDB {
                    ProductID = BasketItem.ProductID,
                    SizeID    = BasketItem.SizeValueId ?? 0,
                    Price     = BasketItem.Price,
                    Quantity  = value
                };
                EditTotal(value);
                BasketDB.AddCount(basketDB);
                BasketItem.Quantity += value;
            }

            entCount.Text = BasketItem.Quantity.ToString();
            if (BasketItem.Quantity < BasketItem.ProductActualQuantity)
            {
                btnPlus.IsEnabled = true;
            }
            if (BasketItem.Quantity > 1)
            {
                btnMinus.IsEnabled = true;
            }

            if (!isError)
            {
                OnePage.redirectApp.basketView.Content = OnePage.redirectApp.basketView.mainGrid;
            }
        }
Esempio n. 4
0
        async Task AddToBasket(int maxCountProduct)
        {
            /// Если пользователь не зарегистрирован или товар из локальной корзины
            if (User.Singleton == null || (oldBasket != null && oldBasket.IsLocalBasket))
            {
                BasketDB basketBD = new BasketDB {
                    ProductID      = ProductItem.ProductsID,
                    Article        = ProductItem.Article,
                    ProductName    = ProductItem.productsDescription.Name,
                    SizeName       = selectSize.Value,
                    Image          = ProductItem.Image,
                    SizeID         = selectSize.Key,
                    Price          = ProductItem.Price,
                    Quantity       = int.Parse(entCount.Text),
                    ProductExpress = ProductItem.Express,
                    IsSchedule     = ProductItem.SchedulesList.Count > 0
                };
                /// Если мы изменяем размер товара в корзине
                if (oldBasket != null)
                {
                    if (oldBasket.SizeValueId != selectSize.Key || oldBasket.Quantity != basketBD.Quantity)
                    {
                        /// Не дает добавить товаров больше чем они есть на складе
                        if (basketBD.Quantity > maxCountProduct)
                        {
                            basketBD.Quantity = maxCountProduct;
                        }
                        BasketDB.Update(basketBD, oldBasket.ProductID, oldBasket.SizeValueId ?? 0);
                    }
                    OnePage.redirectApp.BackToHistory();
                    return;
                }
                else
                {
                    BasketDB basketProfile;
                    if (basketBD.SizeID == 0)
                    {
                        basketProfile = BasketDB.GetItemByID(basketBD.ProductID);
                    }
                    else
                    {
                        basketProfile = BasketDB.GetItem(basketBD.ProductID, basketBD.SizeID);
                    }

                    if (basketProfile != null)
                    {
                        /// Не дает добавить товаров больше чем они есть на складе
                        if (basketBD.Quantity + basketProfile.Quantity > maxCountProduct)
                        {
                            basketBD.Quantity = maxCountProduct - basketProfile.Quantity;
                        }
                    }
                    BasketDB.AddCount(basketBD);
                }
            }
            else                 /// Если залогинен
            {
                Basket basket = new Basket {
                    ProductID   = ProductItem.ProductsID,
                    SizeValueId = selectSize.Key,
                    Quantity    = int.Parse(entCount.Text)
                };
                /// Если мы изменяем размер товара в корзине
                if (oldBasket != null)
                {
                    if (oldBasket.SizeValueId != selectSize.Key || oldBasket.Quantity != basket.Quantity)
                    {
                        /// Удаляем позицию товара из заказа
                        oldBasket.Quantity = -oldBasket.Quantity;
                        try {
                            await Basket.PushToBasketAsync(oldBasket);
                        } catch (Exception) {
                            eventRefresh  = null;
                            eventRefresh += (obj, evn) => {
                                Button content = obj as Button;
                                content.IsEnabled = false;
                                AddToBasket(maxCountProduct).Wait();
                            };
                            Content = OnePage.mainPage.ShowMessageError(eventRefresh);
                            return;
                        }
                        /// Не дает добавить товаров больше чем они есть на складе
                        if (basket.Quantity > maxCountProduct)
                        {
                            basket.Quantity = maxCountProduct;
                        }
                        try {
                            await Basket.PushToBasketAsync(basket);
                        } catch (Exception) {
                            eventRefresh  = null;
                            eventRefresh += (obj, evn) => {
                                Button content = obj as Button;
                                content.IsEnabled = false;
                                AddToBasket(maxCountProduct).Wait();
                            };
                            Content = OnePage.mainPage.ShowMessageError(eventRefresh);
                            return;
                        }
                    }
                    OnePage.redirectApp.BackToHistory();
                    return;
                }
                else                     /// Если перешли в товар НЕ из корзины
                {
                    List <Basket> basketProfileList;
                    try {
                        basketProfileList = await Basket.GetProductInBasketAsync();
                    } catch (Exception) {
                        eventRefresh  = null;
                        eventRefresh += (obj, evn) => {
                            Button content = obj as Button;
                            content.IsEnabled = false;
                            AddToBasket(maxCountProduct).Wait();
                        };
                        Content = OnePage.mainPage.ShowMessageError(eventRefresh);
                        return;
                    }
                    Basket basketProfile;
                    if (basket.SizeValueId != null)
                    {
                        basketProfile = basketProfileList.SingleOrDefault(g => g.ProductID == basket.ProductID && g.SizeValueId == basket.SizeValueId);
                    }
                    else
                    {
                        basketProfile = basketProfileList.SingleOrDefault(g => g.ProductID == basket.ProductID);
                    }

                    if (basketProfile != null)
                    {
                        /// Не дает добавить товаров больше чем они есть на складе
                        if (basket.Quantity + basketProfile.Quantity > maxCountProduct)
                        {
                            basket.Quantity = maxCountProduct - basketProfile.Quantity;
                        }
                    }
                    try {
                        await Basket.PushToBasketAsync(basket);
                    } catch (Exception) {
                        eventRefresh  = null;
                        eventRefresh += (obj, evn) => {
                            Button content = obj as Button;
                            content.IsEnabled = false;
                            AddToBasket(maxCountProduct).Wait();
                        };
                        Content = OnePage.mainPage.ShowMessageError(eventRefresh);
                        return;
                    }
                }
            }
        }