Esempio n. 1
0
        public JsonResult AddProduct(AddProductSaleView view)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var saleDetailBk  = db.SaleDetailBkps.Where(odb => odb.User == User.Identity.Name && odb.ProductId == view.ProductId).FirstOrDefault();
                    var barCode       = db.BarCodes.Where(bc => bc.Bar == view.BarCode).FirstOrDefault();
                    var cellarProduct = db.CellarProducts.Where(cp => cp.ProductId == barCode.ProductId).FirstOrDefault();
                    var producto      = db.Products.Where(pr => pr.ProductId == cellarProduct.ProductId).FirstOrDefault();
                    view.ProductId = producto.ProductId;

                    if (saleDetailBk == null)
                    {
                        saleDetailBk = new SaleDetailBk
                        {
                            User          = User.Identity.Name,
                            Description   = producto.Description,
                            Price         = producto.Price,
                            ProductId     = producto.ProductId,
                            Quantity      = 1,
                            IVAPercentage = 1,   //view.IVAPercentage,
                            DiscountRate  = 1,   //view.DiscountRate,
                            KardexId      = 100, //TODO quitar la variable estatica cuando se tenga kardex listo.
                        };

                        if (cellarProduct.Stock > 1)
                        {
                            db.SaleDetailBkps.Add(saleDetailBk);
                        }
                    }
                    else
                    {
                        if (cellarProduct.Stock > 1)
                        {
                            saleDetailBk.Quantity       += 1;
                            db.Entry(saleDetailBk).State = EntityState.Modified;
                        }
                    }

                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    var errormsg = ex.HResult.ToString();
                    if (errormsg != null)
                    {
                        int errorcode = 400;
                        return(Json(errorcode));
                    }
                }
            }

            return(Json(200));
        }
Esempio n. 2
0
        public ActionResult SearchCodeBar(AddProductSaleView barcode2)
        {
            if (ModelState.IsValid)
            {
                if (barcode2 != null)
                {
                    try
                    {
                        var barCode = db.BarCodes.Where(bc => bc.Bar == barcode2.BarCode).FirstOrDefault();

                        if (barCode != null)
                        {
                            var cellarProduct = db.CellarProducts.Where(cp => cp.ProductId == barCode.ProductId).FirstOrDefault();
                            var producto      = db.Products.Where(pr => pr.ProductId == cellarProduct.ProductId).FirstOrDefault();
                            barcode2.ProductId = producto.ProductId;

                            var response = new ModalSaleView
                            {
                                Description = producto.Description,
                                Price       = producto.Price,
                                ProductId   = producto.ProductId,
                                Barcode     = barCode.Bar
                            };

                            return(PartialView("ModalDetail", response));
                        }
                        else
                        {
                            return(Json(404));
                        }
                    }

                    catch (Exception ex)
                    {
                        var errormsg = ex.HResult;
                        return(Json(errormsg));
                    }
                }

                else
                {
                    var nullmessage = "No se encontro ningun resultado";
                    return(Json(nullmessage));
                }
            }

            return(Json(404));
        }