Exemple #1
0
        public ActionResult Save(string data)
        {
            JavaScriptSerializer jsonSerialiser     = new JavaScriptSerializer();
            SaveSalesViewModel   SavesalesViewModel = jsonSerialiser.Deserialize <SaveSalesViewModel>(data);
            Client client = new Client();

            Sales sales = CreateSales(SavesalesViewModel);
            List <SalesProducs> salesProducs = CreateSalesProductList(SavesalesViewModel);

            if (SavesalesViewModel.ClientId != 0)
            {
                sales.Clients.Add(GetClient(SavesalesViewModel.ClientId));
            }

            if (SavesalesViewModel.DiscountType != 0)
            {
                sales.Discounts.Add(GetDiscount(SavesalesViewModel.DiscountType));
            }

            foreach (SalesProducs salesproduct in salesProducs)
            {
                sales.SalesProducs.Add(salesproduct);
            }

            try
            {
                dgrosStore.Sales.Add(sales);
                dgrosStore.SaveChanges();
                return(Json("1"));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
        }
Exemple #2
0
        private List <SalesProducs> CreateSalesProductList(SaveSalesViewModel saveSalesViewModel = null)
        {
            List <SalesProducs> salesProducsList = new List <SalesProducs>();

            if (saveSalesViewModel == null)
            {
                return(salesProducsList);
            }
            else
            {
                foreach (ProductModelForSalesViewDTO product in saveSalesViewModel.Products)
                {
                    SalesProducs salesProduct = new SalesProducs()
                    {
                        Product   = GetProductById(product.ProductId),
                        Discount  = product.Discount,
                        Quantity  = product.Quantity,
                        UnitPrice = GetProductById(product.ProductId).SellingPrice,
                        SubTotal  = product.SubTotal,
                    };
                    salesProducsList.Add(salesProduct);
                }
                ;
                return(salesProducsList);
            }
        }
Exemple #3
0
        //aqui hay que pasar el dato de la tienda donde se realizo la venta que lo haremos desde variables de seccion
        private Sales CreateSales(SaveSalesViewModel salesViewModel, bool state = true)
        {
            int   StoreId = 1;
            Sales sales   = new Sales()
            {
                Clients       = new List <Client>(),
                StoreId       = StoreId,
                Commentary    = salesViewModel.Commentary,
                Date          = DateTime.Now,
                paymentMethod = salesViewModel.PaymentMethod,
                State         = state,
                SalesProducs  = new List <SalesProducs>(),
                Discounts     = new List <Discount>(),
                Total         = salesViewModel.Total
            };

            return(sales);
        }