public HttpResponseMessage SaveSale(vmSales model)
        {
            int result = 0;

            try
            {
                result = objItemService.SaveSale(model);
            }
            catch (Exception e)
            {
                e.ToString();
            }

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Exemple #2
0
        /// <summary>
        /// Save Data To Database
        /// <para>Use it when save data through a stored procedure</para>
        /// </summary>
        public int SaveSale(vmSales vmodel)
        {
            int       result = 0, saleItemID = 0, saleID = 0;
            tbl_Sales sale = new tbl_Sales(); tbl_Product objItem = new tbl_Product();
            var       items = new List <tbl_SalesItem>();

            string[] valueItems = null; string strItems = string.Empty;
            decimal  price = 0; decimal vat = 25;

            try
            {
                strItems   = vmodel.Items.ToString();
                valueItems = strItems.Split(',');
                if (strItems != "")
                {
                    //---for SalesMaster--------
                    saleID        = GenericFactoryFor_Sale.getMaxVal_int("SaleID", "tbl_Sales");
                    sale.SaleID   = saleID;
                    sale.SaleNo   = "SL-" + saleID;;
                    sale.SaleDate = DateTime.UtcNow;
                    sale.OutletID = vmodel.OutletID;
                    sale.TypeID   = vmodel.TypeID;

                    //---for SalesDetails--------
                    saleItemID = GenericFactoryFor_SalesItem.getMaxVal_int("SaleItemID", "tbl_SalesItem");
                    for (int i = 0; i < valueItems.Length; i++)
                    {
                        int productID = Convert.ToInt32(valueItems[i]);
                        objItem = GenericFactoryFor_Product.FindBy(t => t.ProductID == productID).FirstOrDefault();
                        price   = Convert.ToDecimal(objItem.Price);
                        var item = new tbl_SalesItem
                        {
                            SaleItemID = saleItemID,
                            ProductID  = productID,
                            SaleID     = saleID,
                            Price      = price + vat
                        };

                        items.Add(item);
                        saleItemID++;
                    }
                    using (TransactionScope transaction = new TransactionScope())
                    {
                        if (sale != null)
                        {
                            //GenericFactoryFor_Sale.Insert(sale);
                            //GenericFactoryFor_Sale.Save();
                        }

                        if (items != null)
                        {
                            GenericFactoryFor_SalesItem.InsertList(items.ToList());
                            GenericFactoryFor_SalesItem.Save();
                        }

                        transaction.Complete();
                        result = 1;
                    }
                }
                else
                {
                    result = 0;
                }
            }
            catch (Exception ex)
            {
                result = 0;
                ErrorLog.Log(ex);
                ex.ToString();
            }

            return(result);
        }