Esempio n. 1
0
        public Returner Purchases(int InvoiceID)
        {
            int ProjID = (int)(db.SupplierInvoices.Where(p => p.Id == InvoiceID).SingleOrDefault().ProjectID);
            List <SupplierInvoiceLine> LOSIL = new List <SupplierInvoiceLine>();

            LOSIL = new SupplierInvoiceLine {
                InvoiceId = InvoiceID
            }.GetByInvoiceID().Data as List <SupplierInvoiceLine>;
            foreach (SupplierInvoiceLine 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.Purchase_Operation_Finished_Successfully
            });
        }
        public Returner Add()
        {
            db.SupplierInvoiceLines.Add(this);
            db.SaveChanges();
            var LastInvoiceLine          = db.SupplierInvoiceLines.Where(p => p.Id == this.Id).ToList();
            SupplierInvoiceLine 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
                }
            }).ToList().SingleOrDefault();

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