示例#1
0
        private void btnGuncelle_Click(object sender, EventArgs e)
        {
            if (lstUrunler.SelectedItem == null)
            {
                return;
            }

            Urun seciliUrun        = lstUrunler.SelectedItem as Urun;
            var  guncellenecekUrun = new UrunRepo().UrunBul(seciliUrun.Id); // iki methoda da urunbul demişiki string arayana da id arayana da . Id arayanı kullandık.

            try
            {
                // update i de jenerikle yazalım.
                // update de ki biraz farklı. Öncelikle ürünü bulman lazım. Sonra aşağıya inip update yazıyorsun biriyorusun.
                // açıkçası update e jenerik yazmak çok da mantıklı değil çünkü biraz daha uzun oluyor kod. Ama diğer avantajları da çok olduğundan karışıklık olmasın hepsini jenerik yapalım diyoruz.
                seciliUrun = new ProductRepo().GetByID(seciliUrun.Id); // remdeki o anki instance da ki urunu buldu aktardı buraya.

                seciliUrun.UrunAdi   = txtUrunAdi.Text;
                seciliUrun.Fiyat     = nFiyat.Value;
                seciliUrun.SatistaMi = cbSatistaMi.Checked;
                //new UrunRepo().UrunGuncelle(seciliUrun); // bu eski yöntem di.

                // bu alttakini yazabilmek için getbyıd ile o ürünü bulmuş olmamız lazım.
                new ProductRepo().Update();
                UrunleriYukle();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public ActionResult OrderProduct(int id)
        {
            CartRepo  cr1   = new CartRepo();
            CartModel cart2 = cr1.GetCart(id);

            int    pId   = (int)cart2.ProductID;
            int    q     = (int)cart2.Quantity;
            int    c     = (int)cart2.CustomerID;
            int    tp    = (int)cart2.TotalPrice;
            String pname = cart2.Product.ProductName;

            //orderModel = new OrderModel(15001, c, pId, pname, q, tp, null);
            orderModel = new OrderModel()
            {
                OrderID     = 15001,
                CustomerID  = c,
                ProductID   = pId,
                ProductName = pname,
                Quantity    = q,
                TotalPrice  = tp,
                OrderDate   = null
            };

            Boolean b = op.AddOrder(orderModel);

            if (b == true)
            {
                cr1.DeleteProduct(cart2.CartID);

                pr = new ProductRepo();
                pr.EditProductQuantity(pId, q);
            }

            return(RedirectToAction("ShowOrders"));
        }
示例#3
0
        public async Task <IActionResult> CreateAdd([Bind("Id,ProductId,CustomerId,Quantity,Timestamp")] Order order)
        {
            var check    = new OrderLogic();
            var products = new ProductRepo();

            if (ModelState.IsValid && check.IsWithinInventory(products.GetInventory(_context, order.ProductId), order.Quantity))
            {
                try
                {
                    products.UpdateInventory(_context, order.ProductId, order.Quantity);
                    _context.Add(order);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    _logger.LogInformation(ex, "Something in the order wasn't able to be added");
                }
            }
            var repo = new OrderRepo();

            ViewData["ProductInfo"] = repo.ProductList(_context);
            return(View(order));
        }
示例#4
0
        private void ProcessEans()
        {
            foreach (KeyValuePair <string, string> product in this.RecognizedEan)
            {
                Product entity = null;
                if (!string.IsNullOrEmpty(product.Value))
                {
                    entity = ProductRepo.GetByEan13(product.Value);
                }

                if (entity == null)
                {
                    CWUnrecognizedProduct cw = new CWUnrecognizedProduct(this.Context, product.Key, product.Value);
                    if (cw.ShowDialog().HasValue&& cw.DialogResult.Value)
                    {
                        entity = cw.GetProduct();
                    }
                }

                this.RecognizedProducts.Add(entity);
            }

            //this.SaveProducts();
            this.LoadVisible = false;
            this.ValidateScan();
        }
示例#5
0
        protected void AddCartBtn_Click(object sender, EventArgs e)
        {
            int id     = Convert.ToInt32(Request.QueryString["ID"]);
            int userId = Convert.ToInt32(((User)Session["auth_user"]).Id.ToString());
            int qty    = Convert.ToInt32(TxtQty.Text);

            Product products = ProductRepo.GetProductByID(id);
            bool    isExist  = CartHandler.isExist(id, userId);

            if (isExist == true)
            {
                Cart carts = CartRepo.getCartbyProductIdAndUserId(id, userId);
                qty = qty + carts.Quantity;
            }


            if (qty > products.Stock)
            {
                LblError.Text = "Sorry, This Product Stock is just " + products.Stock;
            }
            else
            {
                if (isExist == false)
                {
                    CartRepo.doInsertProductToCart(id, userId, qty);
                }

                else
                {
                    CartRepo.addQtyProduct(id, userId, qty);
                }

                Response.Redirect("./ViewProduct.aspx");
            }
        }
示例#6
0
        public ActionResult Edit(int id)
        {
            ViewBag.Product = new SelectList(ProductRepo.Get(), "Id", "Name");
            ProductViewModel model = ProductRepo.GetById(id);

            return(View("_Edit", model));
        }
示例#7
0
        public async Task <HttpResponseMessage> GetProductTypes()
        {
            var repo = new ProductRepo(_dbConnString);
            var res  = await repo.GetProductTypesAsync();

            return(Request.CreateResponse(HttpStatusCode.OK, res));
        }
示例#8
0
        public IQueryable <Product> GetProducts()
        {
            var repo             = new ProductRepo();
            var productsFromRepo = repo.GetAllProducts().AsQueryable();

            return(productsFromRepo);
        }
示例#9
0
        private void btnGetCategories_Click(object sender, EventArgs e)
        {
            var urun        = new ProductRepo().GetAll();
            var kategori    = new CategoryRepo().GetAll();
            var kategoriler = from p in urun
                              join k in kategori on p.CategoryId equals k.CategoryId

                              group new
            {
                p,
                k
            } by new
            {
                k.CategoryName
            }
            into gp
            orderby gp.Key.CategoryName ascending
                select new
            {
                CategoryName = gp.Key.CategoryName,

                Total = gp.Sum(x => x.p.ProductStock)
            };

            lstReport.DataSource = kategoriler.ToList();
        }
示例#10
0
        public static int addProduct(int catId, int vendorId, string name, int price
                                     , string desc, int subcatId)
        {
            int x = ProductRepo.insertProduct(catId, vendorId, name, price, desc, subcatId);

            return(x);
        }
示例#11
0
        public void GetProductById_Returns_Product()
        {
            var productRepo = new ProductRepo();
            var product     = productRepo.GetById(1);

            Assert.IsType <Product>(product);
        }
示例#12
0
 public frmStocks()
 {
     _errorLogs   = new ErrorLogs();
     _repoProduct = new ProductRepo();
     _repoStock   = new StockRepo();
     InitializeComponent();
 }
示例#13
0
        public List <ProductViewModel> GetAllProductsList()
        {
            var repo = new ProductRepo();
            List <ProductViewModel> productsList = repo.GetAllProductsList().ToList();

            return(productsList);
        }
示例#14
0
        public ActionResult ShowQuantity(String searchText)
        {
            ProductRepo productRepo = new ProductRepo();
            var         list        = productRepo.SearchProducts(searchText);

            return(View(list));
        }
示例#15
0
        public ActionResult ProductEdit(int id, ProductModel productModel)
        {
            ProductRepo productRepo = new ProductRepo();
            Boolean     b           = productRepo.EditProduct(id, productModel);

            return(RedirectToAction("ProductDetails"));
        }
示例#16
0
        public ActionResult ShowDetails(int id)
        {
            ProductRepo productRepo = new ProductRepo();
            var         product     = productRepo.GetProduct(id);

            return(View(product));
        }
示例#17
0
        public ActionResult ShowQuantity()
        {
            ProductRepo productRepo = new ProductRepo();
            var         list        = productRepo.GetAllProducts();

            return(View(list));
        }
        protected List <SelectListItem> GetProductSelectList()
        {
            var products = new ProductRepo().GetAll(x => x.SupProductID == null).OrderBy(x => x.ProductName).ToList();
            List <SelectListItem> prdList = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text  = "Üst ürünü yok",
                    Value = "null"
                }
            };

            foreach (var prd in products)
            {
                if (prd.Products.Any())
                {
                    prdList.Add(new SelectListItem()
                    {
                        Text  = prd.ProductName,
                        Value = prd.Id.ToString()
                    });
                    prdList.AddRange(GetSubProducts(prd.Products.OrderBy(x => x.ProductName).ToList()));
                }
                else
                {
                    prdList.Add(new SelectListItem()
                    {
                        Text  = prd.ProductName,
                        Value = prd.Id.ToString()
                    });
                }
            }

            return(prdList);
        }
        public async Task Update_Product_When_Value_Valid()
        {
            var dbContext = _fixture.Context;


            dbContext.Products.Add(new Product {
                ProductName = "Book 2", Stock = 3, CategoryId = 3, ProviderId = 3, UnitPrice = 1000, Description = "new book", IsNew = true, Status = true,
            });

            dbContext.SaveChanges();

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .Build();

            var _repoUser = IUserServiesMock.UserServices();

            var productRepo = new ProductRepo(dbContext, _repoUser, _hostingEnv, configuration);

            var productController = new ProductController(productRepo);

            var expected = true;

            var result = productController.Put(new ProductRequest {
                ProductId = 1, ProductName = "Book 1", Stock = 3, CategoryId = 3, ProviderId = 3, UnitPrice = 1000, Description = "new book", IsNew = true, Status = true,
            });

            var resultValue = Assert.IsType <OkObjectResult>(result.Result);

            Assert.True(resultValue.Value.Equals(expected));
        }
示例#20
0
        public void GetProducts_Returns_Product()
        {
            var productRepo = new ProductRepo();
            var product     = productRepo.GetAllProducts();

            Assert.IsType <List <Product> >(product);
        }
示例#21
0
 internal ProductModule()
 {
     productRepo          = new ProductRepo();
     productsBrandRepo    = new ProductsBrandRepo();
     productsCategoryRepo = new ProductsCategoryRepo();
     productsProviderRepo = new ProductsProviderRepo();
 }
示例#22
0
        public IEnumerable <Product> GetProducts(string filter)
        {
            var repo     = new ProductRepo();
            var products = repo.GetAllProducts();

            return(products.Where(p => p.Name.Contains(filter)));
        }
示例#23
0
        public ActionResult Add(int?productID)
        {
            // then didnt come from products page
            if (productID == null)
            {
                return(RedirectToAction("Index")); // send them there
            }
            // used to send current qunatity to the page
            string           sessionID = System.Web.HttpContext.Current.Session.SessionID;
            ShoppingCartRepo cartRepo  = new ShoppingCartRepo();
            ProductVisit     cartItem  = cartRepo.GetCartItem(sessionID, (int)productID);

            ProductVM productVM;

            if (cartItem == null)
            {
                ProductRepo pRepo   = new ProductRepo();
                Product     product = pRepo.GetProduct(productID);

                productVM = new ProductVM(product);
                productVM.SetTotalCost(); // quntity times price
                productVM.image    = product.Image.imageTitle;
                productVM.quantity = 1;
            }
            else
            {
                productVM = new ProductVM(cartItem.Product);
                productVM.SetTotalCost(); // quntity times price
                productVM.image    = cartItem.Product.Image.imageTitle;
                productVM.quantity = cartItem.qtyOrdered;
            }

            return(View(productVM));
        }
示例#24
0
        public LossForProduct GetLossForProduct(Guid productId)
        {
            Product        Product     = ProductRepo.Get(x => x.Id == productId);
            LossForProduct LossRecords = new LossForProduct();


            Batch[] ProductInStoreRecords = BatchRepo.GetAll(x => x.ProductId == productId).ToArray();
            Guid[]  ProductInStoreIds     = ProductInStoreRecords.Select(x => x.Id).ToArray();
            Loss[]  LossesForProduct      = LossRepo.GetAll(x => x.Batch.ProductId == productId).OrderBy(x => x.DateOfLoss).ToArray();

            Dictionary <int, Dictionary <Month, double> > LossPerYear = new Dictionary <int, Dictionary <Month, double> >();

            LossPerYear = GroupLossPerYear(LossesForProduct);

            foreach (var item in LossPerYear)
            {
                int Year = item.Key;
                Dictionary <Month, double> LossPerMonth = item.Value;
                LossRecords.LossForProductInYear.Add(new LossForProductInYear()
                {
                    Year = Year, LossPerMonth = LossPerMonth,
                });
            }
            LossRecords.Product = Product;
            return(LossRecords);
        }
示例#25
0
        public void NewProduct(Order order)
        {
            OrderManager manager = OrderManagerFactory.Create();

            while (!isValid)
            {
                ProductRepo repo        = new ProductRepo();
                string      productType = ConsoleIO.GetProduct(repo.LoadProducts());
                Console.WriteLine($"Is this the correct new product: {productType}, Y/N?");
                string correctProduct = Console.ReadLine().ToUpper();
                if (correctProduct == "Y")
                {
                    isValid = true;
                }
                ProductTypeResponse response = manager.FindProductByType(productType);
                if (response.Success)
                {
                    manager.SaveCurrentOrder(order);
                    ConsoleIO.DisplayEditedOrderDetail(order);
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();
                }
                else
                {
                    response.Success = false;
                    response.Message = "An error occurred";
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();
                }
            }
        }
        public async Task Seach_Product_by_Name_When_KeyWord_NotExits_in_ProductList(string keyword)
        {
            //Arrange
            var dbContext = _fixture.Context;

            dbContext.Products.Add(new Product {
                ProductName = "Book 2", Stock = 3, CategoryId = 3, ProviderId = 3, UnitPrice = 1000, Description = "new book 1", IsNew = true, Status = true,
            });
            dbContext.Products.Add(new Product {
                ProductName = "Book 3", Stock = 13, CategoryId = 3, ProviderId = 3, UnitPrice = 500, Description = "new book 2", IsNew = true, Status = true,
            });
            dbContext.SaveChanges();

            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
                                .Build();

            var _repoUser = IUserServiesMock.UserServices();

            var productRepo = new ProductRepo(dbContext, _repoUser, _hostingEnv, configuration);

            var productController = new ProductController(productRepo);
            //Act

            var result = productController.search(keyword);

            //Assert
            var resultValue = Assert.IsType <OkObjectResult>(result.Result.Result);

            var product = resultValue.Value as List <Product>;

            Assert.Equal(product.Count(), 0);
        }
示例#27
0
        public ProductViewModel GetProduct(Guid id)
        {
            var repo = new ProductRepo();
            ProductViewModel product = repo.GetProduct(id);

            return(product);
        }
示例#28
0
        public void GetProductInfoById_Returns_ProductInfo()
        {
            var productInfoRepo = new ProductRepo();
            var productInfo     = productInfoRepo.GetInfoById(1);

            Assert.IsType <ProductInformation>(productInfo);
        }
示例#29
0
        public static void DoReadOnly(Form form)
        {
            ProductRepo db = new ProductRepo();

            foreach (Control control in form.Controls)
            {
                if (control is TextBox txt)
                {
                    txt.ReadOnly = true;
                }
                else if (control is NumericUpDown nm)
                {
                    nm.Enabled = false;
                }
                else if (control is ComboBox cmb)
                {
                    foreach (var item in db.GetAll())
                    {
                        if ((cmb.SelectedItem.GetType() == item.GetType()))
                        {
                            cmb.Enabled = false;
                            break;
                        }
                    }
                }
            }
        }
示例#30
0
        [Route("Products")] //Add Route
        public IActionResult Index()
        {
            ViewBag.Action = "Edit";
            var Products = ProductRepo.Get(orderBy: products => products.OrderBy(g => g.Name)).ToList();

            return(View(Products));
        }
 public ProductBusiness()
 {
     this._repo = new ProductRepo();
 }
 public Products()
 {
     prod = new ProductRepo();
 }