public JsonResult SavePurchase(PurchaseEntryVM p) { bool status = false; if (p != null) { //new purchase object using the data from the viewmodel : PurchaseEntryVM Purchase purchase = new Purchase { ID = p.ID, Date = p.Date, SupplierID = p.SupplierID, Amount = p.Amount, Discount = p.Discount, Tax = p.Tax, GrandTotal = p.GrandTotal, IsPaid = p.IsPaid, Description = p.Description, LastUpdated = DateTime.Now }; purchase.PurchaseItems = new List<PurchaseItem>(); //populating the PurchaseItems from the PurchaseItems within ViewModel : PurchaseEntryVM foreach (var i in p.PurchaseItems) { purchase.PurchaseItems.Add(i); } //add purchase // finally save changes. service.AddPurchaseAndPurchseItems(purchase); service.InsertOrUpdateInventory(p.PurchaseItems); //if everything is sucessful, set status to true. status = true; } // return the status in form of Json return new JsonResult { Data = new { status = status } }; }
// GET: PurchaseEntry /// <summary> /// Main page for entering new purchase records. /// </summary> /// <returns></returns> /// <remarks></remarks> public ActionResult Index() { var vm = new PurchaseEntryVM(); return View(vm); }