public async Task <ActionResult> Create(Sale sale)
        {
            if (sale.ManagerId == 0 || sale.ProductId == 0 || sale.CustomerId == 0)
            {
                ModelState.AddModelError("", "All fields must be filled");

                return(View("Create", SaleCreateViewModel.Create()));
            }

            await Task.Run(() => SaleService.CreateSale(sale));

            return(View("Index"));
        }
예제 #2
0
        public ActionResult Create(SaleCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (_service.CreateSale(model))
            {
                TempData["SaveResult"] = "Sale was added.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Sale could not be created.");
            return(View(model));
        }
예제 #3
0
        private void PlaceOrderButton_Click(object sender, EventArgs e)
        {
            SaleService saleService = new SaleService();

            if (quantityTextBox.Text == "")
            {
                MessageBox.Show("Plaese Mention A Quantity", "Quantity");
            }

            int result = saleService.CreateSale(customerNameTextBox.Text, customerId, productNameTextBox.Text, productId, saleDateTimePicker.Value.ToString("MM/dd/yyyy"), Convert.ToInt32(quantityTextBox.Text), unitPrice, availableQuantity);

            if (result > 0)
            {
                MessageBox.Show("Order created successfully", "Order");
            }
            else
            {
                MessageBox.Show("Insufficient Stock", "Order");
            }
        }
예제 #4
0
        public ActionResult Create(SaleCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // TODO: Add insert logic here
                    //_saleApplicationService.CreateSale(model.CustomerId, model.PaymentDate, model.Productindex,
                    //    model.Quantity);
                    var list = new List <SaleLineItem>();
                    foreach (var item in sales)
                    {
                        var saleLineItem = new SaleLineItem()
                        {
                            ProductId = item.ProductId,
                            Quantity  = item.QTY,
                            UnitPrice = item.Price
                        };
                        list.Add(saleLineItem);
                    }

                    _saleApplicationService.CreateSale(model.CustomerId, model.PaymentDate, list);

                    // reduce qty from product table
                    foreach (var product1 in list)
                    {
                        var productqty = _context.Products.FirstOrDefault(p => p.Id == product1.ProductId);
                        if (productqty != null)
                        {
                            productqty.CurrentQTY -= product1.Quantity;
                            _context.SaveChanges();
                        }
                    }

                    sales = null;
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex);
                }
            }

            var customer = _context.Customers
                           .Select(s => new SaleCreateViewModel()
            {
                CustomerId       = s.Id,
                CustomerFullName = s.FirstName + " " + s.LastName
            });

            var product = _context.Products
                          .Select(s => new SaleCreateViewModel()
            {
                Productindex      = s.Id,
                ProductName       = s.ProductName,
                ProductFullDetail = s.ProductName + " , $" + s.Price
            }).ToList();

            //model.CustomerSelectList = new SelectList(customer, "Id", "FirstName");
            //model.ProductSelectList = new SelectList(product, "Id", "Name");

            model.CustomerSelectList = new SelectList(customer, "CustomerId", "CustomerFullName");
            model.ProductSelectList  = new SelectList(product, "Productindex", "ProductName");

            return(View(model));
        }