Exemple #1
0
        public bool PerformSale(ProductSaleModel model)
        {
            if (model != null)
            {
                var productToEdit = _unitOfWork.ProductRepository.Get().Where(p => p.ID == model.ProductId).FirstOrDefault();

                if (productToEdit != null)
                {
                    if (productToEdit.UnitsAvailable < model.UnitsSold)
                    {
                        returnMessages.Add("Inventory is very low " + productToEdit.Name);
                    }
                    else
                    {
                        Sale productSale = new Sale();
                        productSale.ProductId      = model.ProductId;
                        productSale.UnitsSold      = model.UnitsSold;
                        productSale.Discount       = model.Discount;
                        productSale.PaymentType    = model.PaymentType;
                        productSale.SaleDate       = DateTime.Now;
                        productSale.UnitsAvailable = productToEdit.UnitsAvailable;

                        _unitOfWork.SaleRepository.Insert(productSale);

                        productToEdit.UnitsAvailable = productToEdit.UnitsAvailable - Convert.ToInt16(model.UnitsSold);
                        _unitOfWork.ProductRepository.Update(productToEdit);

                        _unitOfWork.Save();
                        returnMessages.Add("Purchase completed " + productToEdit.Name);
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #2
0
        public ActionResult ProductSale(ProductSaleModel model)
        {
            var result = PerformSale(model);

            if (returnMessages.Count > 0)
            {
                ViewBag.DisplayMessage     = returnMessages[0].ToString();
                ViewData["DisplayMessage"] = returnMessages[0].ToString();
            }
            ProductSaleModel modelInfo = GetDefaultModel();

            return(View(modelInfo));
        }
Exemple #3
0
        public HttpResponseMessage Get([FromUri] int id = 0)
        {
            try
            {
                if (id == 0)
                {
                    //Get all sale info
                    var dbListingOfSalesToReturn = _unitOfWork.SaleRepository.Get();

                    var tempListToReturn = new List <ProductSaleModel>();
                    foreach (var item in dbListingOfSalesToReturn)
                    {
                        ProductSaleModel saleProd = new ProductSaleModel();
                        saleProd.SaleId    = item.SaleId;
                        saleProd.ProductId = item.ProductId;
                        var productInfo = _unitOfWork.ProductRepository.Get().Where(p => p.ID == item.ProductId).FirstOrDefault();
                        saleProd.ProductName    = productInfo.Name;
                        saleProd.UnitsSold      = item.UnitsSold;
                        saleProd.SaleDate       = item.SaleDate;
                        saleProd.Discount       = item.Discount;
                        saleProd.PaymentType    = item.PaymentType;
                        saleProd.UnitsAvailable = item.UnitsAvailable;

                        tempListToReturn.Add(saleProd);
                    }


                    return(Request.CreateResponse(HttpStatusCode.OK, tempListToReturn.ToList()));
                }
                else
                {
                    //Get specified sale info
                    var dbSaleToReturn    = _unitOfWork.SaleRepository.Get().Where(p => p.ProductId == id).FirstOrDefault();
                    var finalSaleToReturn = new FoodInventory.Data.Models.DTOs.SalesDTO
                    {
                        SaleId      = dbSaleToReturn.SaleId,
                        ProductId   = dbSaleToReturn.ProductId,
                        UnitsSold   = dbSaleToReturn.UnitsSold,
                        SaleDate    = dbSaleToReturn.SaleDate,
                        Discount    = dbSaleToReturn.Discount,
                        PaymentType = dbSaleToReturn.PaymentType
                    };

                    return(Request.CreateResponse(HttpStatusCode.OK, finalSaleToReturn));
                }
            }
            catch (Exception exc)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, exc.ToString()));
            }
        }
Exemple #4
0
        public ProductSaleModel GetDefaultModel()
        {
            var productInfo = _unitOfWork.ProductRepository.Get();
            List <ProductImageModel> prodList  = new List <ProductImageModel>();
            ProductSaleModel         modelInfo = new ProductSaleModel();

            foreach (var product in productInfo)
            {
                ProductImageModel modelinfo = new ProductImageModel();
                modelinfo.ID   = product.ID;
                modelinfo.Name = product.Name;
                prodList.Add(modelinfo);
            }
            modelInfo.ProductOptions = prodList.ToList();
            return(modelInfo);
        }
 public void Edit(int id, ProductSaleModel model)
 {
     using (var uow = new UnitOfWork(new DataContext()))
     {
         var obj = uow.ProductSales.Get(id);
         obj.CustomerName    = model.CustomerName;
         obj.Discount        = model.Discount;
         obj.ProductID       = model.ProductID;
         obj.Quantity        = model.Quantity;
         obj.UnitPrice       = model.UnitPrice;
         obj.OutletSaleName  = model.OutletSaleName;
         obj.isBuyOneTakeOne = model.IsBuyOneTakeOne;
         uow.ProductSales.Edit(obj);
         uow.Complete();
     }
 }
 public ProductSaleModel Get(int productSaleID)
 {
     using (var uow = new UnitOfWork(new DataContext()))
     {
         var obj   = uow.ProductSales.Get(productSaleID);
         var model = new ProductSaleModel();
         model.CustomerName    = obj.CustomerName;
         model.Date            = obj.CreateTimeStamp;
         model.Discount        = obj.Discount;
         model.ProductID       = obj.ProductID;
         model.Quantity        = obj.Quantity;
         model.UnitPrice       = obj.UnitPrice;
         model.IsBuyOneTakeOne = obj.isBuyOneTakeOne;
         model.AdditionalQty   = obj.Quantity * 2;
         model.OutletSaleName  = obj.OutletSaleName;
         return(model);
     }
 }
 public void Add(ProductSaleModel model)
 {
     using (var uow = new UnitOfWork(new DataContext()))
     {
         var obj = new ProductSale();
         obj.CreateTimeStamp = model.Date;
         obj.CustomerName    = model.CustomerName;
         obj.Discount        = model.Discount;
         obj.ProductID       = model.ProductID;
         obj.Quantity        = model.Quantity;
         obj.isBuyOneTakeOne = model.IsBuyOneTakeOne;
         obj.UnitPrice       = model.UnitPrice;
         obj.OutletSaleName  = model.OutletSaleName;
         uow.ProductSales.Add(obj);
         uow.Complete();
         model.ID = obj.ProductSaleID;
     }
 }
 public void Save()
 {
     try
     {
         if (!ValidateFields(pnlUpdate))
         {
             LocalUtils.ShowValidationFailedMessage(this);
         }
         else
         {
             var model = new ProductSaleModel();
             model.CustomerName    = txtCustomerName.Text;
             model.Date            = dtDate.Value;
             model.Discount        = LocalUtils.ConvertToDouble(txtDiscount.Text);
             model.IsBuyOneTakeOne = chkIsBuyOneTakeOne.Checked;
             model.Quantity        = LocalUtils.ConvertToDouble(txtQuantity.Text);
             model.UnitPrice       = LocalUtils.ConvertToDouble(txtUnitPrice.Text);
             model.OutletSaleName  = cboOutletSaleName.Text;
             model.ProductID       = int.Parse(((ItemX)cboProducts.SelectedItem).Value);
             // get id
             if (productSaleID != 0)
             {
                 Factories.CreateProductSale().Edit(productSaleID, model);
                 LocalUtils.ShowSaveMessage(this);
             }
             else
             {
                 Factories.CreateProductSale().Add(model);
                 productSaleID = model.ID;
                 LocalUtils.ShowSaveMessage(this);
             }
         }
     }
     catch (ApplicationException ex)
     {
         LocalUtils.ShowErrorMessage(this, ex.Message);
     }
     catch (Exception ex)
     {
         LocalUtils.ShowErrorMessage(this, ex.ToString());
     }
 }
Exemple #9
0
        public ActionResult ProductSale()
        {
            ProductSaleModel modelInfo = GetDefaultModel();

            return(View(modelInfo));
        }