Ejemplo n.º 1
0
        public static void DoTransactionAgain()
        {
            Console.Write(@"Thank you for shopping with us.

Would you like to do more transactions (y/n): ");

            string answer = Console.ReadLine().ToLower();

            while (!(answer.Equals("y") || answer.Equals("n")))
            {
                InvalidInputHandler.EraseInvalidInput(-1);
                answer = Console.ReadLine();
            }

            if (answer.Equals("y"))
            {
                Console.Clear();
                _cartManager.ResetList();
                ProductUI.ProductDisplay();
            }
            else if (answer.Equals("n"))
            {
                Environment.Exit(0);
            }
        }
Ejemplo n.º 2
0
        public void UpdateProduct(ProductData productData, int productId, decimal value)
        {
            var productUI = new ProductUI();

            productUI.UpdateProduct(productData, productId, value, "inc");
            var logger = new Logger();

            logger.SaveIntoFile("The product`s quantity was successfully changed");
        }
Ejemplo n.º 3
0
        private void setProductsTable(List <Product> list)
        {
            DataTable table = ProductUI.getDataTable(list);

            table_products.DataSource = table;
            table_products.DataBind();

            // set viewstate for sorting
            ViewState["dirState"] = table;
            ViewState["sortdr"]   = "Asc";
        }
Ejemplo n.º 4
0
        public static void DisplayService(int serviceId = 0)
        {
            CartManager cartManager = new CartManager();

            Console.Clear();

            if (cartManager.RetrieveAll().Count > 0)
            {
                CartUI.CartDisplay();
            }

            ProductUI.ProductDisplay();
        }
Ejemplo n.º 5
0
        public IActionResult AddOrEdit(ProductUI productUI)
        {
            if (productUI.Id == 0)
            {
                HttpResponseMessage response = GlobalVariables.WebApiClent.PostAsJsonAsync("Product", productUI).Result;
            }
            else
            {
                var content = new StringContent(JsonConvert.SerializeObject(productUI), Encoding.UTF8, "application/json");

                HttpResponseMessage response = GlobalVariables.WebApiClent.PutAsJsonAsync
                                                   ("Product/" + productUI.Id, content).Result;
                if (response.IsSuccessStatusCode)
                {
                }
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
 public Order AddOrderItem(ProductData productData, Buyer buyer, int id)
 {
     var product = new Product();
     var productUI = new ProductUI();
     product = productUI.AddProductToOrder(productData);
     var buyerClient = new BuyerInterface();
     var orderUI = new OrderUI();
     var totalPrice = product.Price;
     var val = orderUI.GetItemsCount();
     var logger = new Logger();
     logger.SaveIntoFile(product.Name + " was added to the order");
     var value = productUI.UpdateProduct(productData,product.Id, val,"dec");
     totalPrice *= value;
     var promo = buyerClient.GetPromo();
     var discount = product.ProductDiscount;
     if (product.DiscountPromoCode.Equals(promo))
     {
         discount += product.PersonalDiscount;
     }
     totalPrice = GetDiscount(totalPrice, discount);
     var order = new Order(id,product, value, discount, 0.0m, totalPrice, Order.OrderStatus.Undefined, buyer);
     return order;
 }
Ejemplo n.º 7
0
        public static List <OfferUI> GetAllOfferByProductIds(Dictionary <Int64, int> LstProduct, Int64 CityId)
        {
            Query innerQuery = new Query(SupplierProduct.TableSchema);

            innerQuery.Where(SupplierProduct.Columns.ProductId, WhereComparision.In, LstProduct.Select(r => r.Key).ToList());
            innerQuery.AddWhere(SupplierProduct.Columns.Price, WhereComparision.GreaterThan, 0);
            innerQuery.Select(SupplierProduct.Columns.SupplierId).GroupBy(SupplierProduct.Columns.SupplierId);
            innerQuery.AddSelectLiteral(" COUNT(" + SupplierProduct.Columns.SupplierId + ") as `suppliercount`");
            int          count     = LstProduct.Count;
            List <Int64> Suppliers = new List <Int64>();

            using (DataReaderBase reader = innerQuery.ExecuteReader())
            {
                while (reader.Read())
                {
                    if (Convert.ToInt32(reader["suppliercount"]) == count)
                    {
                        Suppliers.Add(Convert.ToInt64(reader[SupplierProduct.Columns.SupplierId]));
                    }
                }
            }

            Query CityInnerQuery = new Query(SupplierCity.TableSchema);

            CityInnerQuery.Where(SupplierCity.Columns.CityId, WhereComparision.EqualsTo, CityId);
            CityInnerQuery.Select(SupplierCity.Columns.SupplierId).Distinct();

            if (Suppliers.Count == 0 || CityInnerQuery.ExecuteScalarList <Int64>().Count() == 0)
            {
                return(null);
            }

            Query qry = new Query(AppSupplier.TableSchema);

            qry.SelectAllTableColumns();
            qry.Join(JoinType.InnerJoin, SupplierProduct.TableSchema, SupplierProduct.TableSchema.SchemaName,
                     new JoinColumnPair(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, SupplierProduct.Columns.SupplierId));
            qry.Join(JoinType.LeftJoin, Comment.TableSchema, Comment.TableSchema.SchemaName,
                     new JoinColumnPair(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, Comment.Columns.SupplierId));

            qry.AddSelect(SupplierProduct.TableSchema.SchemaName, SupplierProduct.Columns.ProductId, SupplierProduct.Columns.ProductId);
            qry.AddSelect(SupplierProduct.TableSchema.SchemaName, SupplierProduct.Columns.Price, SupplierProduct.Columns.Price);
            qry.AddSelect(SupplierProduct.TableSchema.SchemaName, SupplierProduct.Columns.Gift, SupplierProduct.Columns.Gift);
            qry.Where(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, WhereComparision.In, Suppliers);
            qry.AddWhere(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, WhereComparision.In, CityInnerQuery);
            qry.AddWhere(SupplierProduct.TableSchema.SchemaName, SupplierProduct.Columns.ProductId, WhereComparision.In, LstProduct.Select(r => r.Key).ToList());
            qry.AddWhere(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.IsDeleted, WhereComparision.NotEqualsTo, true);
            qry.AddWhere(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.IsLocked, WhereComparision.NotEqualsTo, true);
            qry.AddWhere(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.Status, WhereComparision.NotEqualsTo, false);

            qry.AddSelectLiteral("(SELECT avg(" + Comment.Columns.Rate + ") from " + Comment.TableSchema.SchemaName + " where "
                                 + Comment.TableSchema.SchemaName + "." + Comment.Columns.SupplierId + "=" + AppSupplier.TableSchema.SchemaName + "." + AppSupplier.Columns.SupplierId +
                                 " AND " + Comment.TableSchema.SchemaName + "." + Comment.Columns.Status + "=" + (int)CommentStatus.Approved + ")", "AvgRate");
            qry.AddSelectLiteral("(SELECT Count(" + Comment.Columns.Rate + ") from " + Comment.TableSchema.SchemaName + " where " +
                                 Comment.TableSchema.SchemaName + "." + Comment.Columns.SupplierId + "=" + AppSupplier.TableSchema.SchemaName + "." + AppSupplier.Columns.SupplierId +
                                 " AND " + Comment.TableSchema.SchemaName + "." + Comment.Columns.Status + "=" + (int)CommentStatus.Approved + ")", "numberOfComments");
            qry.AddSelect(AppSupplier.TableSchema.SchemaName, AppSupplier.Columns.SupplierId, AppSupplier.Columns.SupplierId);
            qry.GroupBy(AppSupplier.Columns.SupplierId);
            qry.GroupBy(SupplierProduct.Columns.ProductId);
            var suppliersSumDic = new Dictionary <Int64, OfferUI>();

            using (DataReaderBase reader = qry.ExecuteReader())
            {
                while (reader.Read())
                {
                    Int64 supplierId = reader[SupplierProduct.Columns.SupplierId] != null?Convert.ToInt64(reader[SupplierProduct.Columns.SupplierId]) : 0;

                    Int64 productId = reader[SupplierProduct.Columns.ProductId] != null?Convert.ToInt64(reader[SupplierProduct.Columns.ProductId]) : 0;

                    AppSupplier supplier = AppSupplier.FetchByID(supplierId);
                    if (supplier != null && productId > 0)
                    {
                        decimal price        = Convert.ToDecimal(reader["Price"]);
                        string  gift         = reader["Gift"].ToString();
                        int     amount       = LstProduct[productId];
                        decimal productPrice = price * amount;

                        if (!suppliersSumDic.ContainsKey(supplierId))
                        {
                            suppliersSumDic[supplierId] = new OfferUI
                            {
                                SupplierName     = supplier.BusinessName,
                                SupplierId       = supplierId,
                                MastercardCode   = supplier.MastercardCode,
                                Products         = new List <ProductUI>(),
                                AvgRate          = reader["AvgRate"] == DBNull.Value ? 0 : Convert.ToDouble(reader["AvgRate"]),
                                NumberOfComments = reader["numberOfComments"] == DBNull.Value ? 0 : Convert.ToInt32(reader["numberOfComments"])
                            }
                        }
                        ;

                        var product = new ProductUI {
                            ProductId    = productId,
                            ProductPrice = productPrice,
                            Amount       = amount.ToString(),
                        };

                        suppliersSumDic[supplierId].Products.Add(product);
                        suppliersSumDic[supplierId].TotalPrice += productPrice;
                        suppliersSumDic[supplierId].Gift       += gift;
                    }
                }
            }
            return(suppliersSumDic.Values.OrderBy(x => x.TotalPrice).ToList());
        }