Exemplo n.º 1
0
        public ActionResult UpdateOpeningStock()
        {
            var model     = new OpeningStockVM();
            int companyId = Convert.ToInt32(Session["CompanyID"]);

            model.Products = db.Products
                             .Where(x => x.IsActive == true && x.Company_Id == companyId)
                             .ToList();

            var year_id = Convert.ToInt32(Session["FinancialYearID"]);

            model.FinancialYear = db.FinancialYears
                                  .Where(x => x.Id == year_id)
                                  .FirstOrDefault();

            model.Transactions = db.Transactions
                                 .Where(x => x.FinancialYear_Id == year_id)
                                 .ToList();

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult UpdateOpeningStock(List <Transaction> Transactions)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var CompanyId = Convert.ToInt32(Session["CompanyID"]);
                    var year_id   = Convert.ToInt32(Session["FinancialYearID"]);

                    var t = db.Transactions
                            .Where(x => x.FinancialYear_Id == year_id)
                            .ToList();

                    foreach (var item in Transactions)
                    {
                        var product = t
                                      .Where(x => x.product_id == item.product_id)
                                      .Where(x => x.FinancialYear_Id == year_id)
                                      .FirstOrDefault();

                        if (product == null)
                        {
                            db.Transactions.Add(new Transaction()
                            {
                                product_id       = item.product_id,
                                Type             = "opening stock",
                                FinancialYear_Id = year_id,
                                Company_Id       = CompanyId,
                                Created          = DateTime.Now,
                                Updated          = DateTime.Now,
                                Quantity         = item.Quantity
                            });
                        }
                        else
                        {
                            product.Quantity        = item.Quantity;
                            product.Updated         = DateTime.Now;
                            db.Entry(product).State = EntityState.Modified;
                        }
                    }

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception e)
                {
                }
            }

            var model     = new OpeningStockVM();
            int companyId = Convert.ToInt32(Session["CompanyID"]);

            model.Products = db.Products
                             .Where(x => x.IsActive == true && x.Company_Id == companyId)
                             .ToList();

            var yid = Convert.ToInt32(Session["FinancialYearID"]);

            model.FinancialYear = db.FinancialYears
                                  .Where(x => x.Id == yid)
                                  .FirstOrDefault();

            model.Transactions = db.Transactions
                                 .Where(x => x.FinancialYear_Id == yid)
                                 .ToList();

            return(View(model));
        }