Ejemplo n.º 1
0
        public Returner Sells(int InvoiceID)
        {
            int ProjID = (int)(db.CustomerInvoices.Where(p => p.Id == InvoiceID).SingleOrDefault().ProjectID);
            List <CustomerInvoiceLine> LOSIL = new List <CustomerInvoiceLine>();

            LOSIL = new CustomerInvoiceLine {
                InvoiceId = InvoiceID
            }.GetByInvoiceID().Data as List <CustomerInvoiceLine>;
            foreach (CustomerInvoiceLine item in LOSIL)
            {
                var StockToUpdate = db.Stocks.Where(p => p.ProjectID == ProjID && p.ProductID == item.ProductId).SingleOrDefault();
                StockToUpdate.Quantity -= item.Qty;
                db.SaveChanges();
                StockTransaction ST = new StockTransaction
                {
                    Date      = DateTime.UtcNow.AddHours(3),
                    ProductID = StockToUpdate.ProductID,
                    Quantity  = -item.Qty,
                    StockID   = StockToUpdate.Id,
                    Type      = (int)StockTransactionsTypes.بيع
                };
                db.StockTransactions.Add(ST);
                db.SaveChanges();
            }
            return(new Returner
            {
                Message = Message.Sell_Operation_Finished_Successfully
            });
        }
Ejemplo n.º 2
0
        public Returner Add()
        {
            db.CustomerInvoiceLines.Add(this);
            db.SaveChanges();
            var LastInvoiceLine          = db.CustomerInvoiceLines.Where(p => p.Id == this.Id).ToList();
            CustomerInvoiceLine SingleIL = LastInvoiceLine.SingleOrDefault();
            var prod = db.Products.Where(p => p.Id == SingleIL.ProductId).SingleOrDefault();

            LastInvoiceLine.FirstOrDefault().Product = prod;
            var LastInvoiceLineInJSON = (from IL in LastInvoiceLine
                                         select new
            {
                IL.Id,
                IL.Price,
                IL.Qty,
                IL.Total,
                Product = new
                {
                    IL.Product.ProductName,
                    IL.Product.Id
                }
            }).ToList().SingleOrDefault();

            return(new Returner
            {
                Data = LastInvoiceLine.SingleOrDefault(),
                DataInJSON = LastInvoiceLineInJSON.ToJSON()
            });
        }