public ActionResult AddCostSheetItemPartial(CostSheetItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                var costSheetItem = new CostSheetItem
                {
                    Quantity    = model.Quantity,
                    CostSheetId = model.CostSheetId,
                    ItemId      = model.ItemId
                };

                ViewBag.ItemId = new SelectList(db.Items, "ItemId", "ItemPrice");

                db.CostSheetItems.Add(costSheetItem);
                db.SaveChanges();

                return(PartialView());
            }

            return(PartialView(model));
        }
Exemplo n.º 2
0
        public ActionResult Create(CostSheetItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                var costSheet = db.CostSheets.Find(model.CostSheetId);

                if (costSheet == null)
                {
                    return(HttpNotFound());
                }

                var costSheetItem = new CostSheetItem
                {
                    Quantity    = model.Quantity,
                    ItemId      = model.ItemId,
                    CostSheetId = model.CostSheetId
                };


                db.CostSheetItems.Add(costSheetItem);
                db.SaveChanges();

                ViewBag.ItemId = new SelectList(db.Items, "ItemId", "ItemPrice");

                //ViewBag.ItemId = new SelectList(db.Items, "ItemId", "Name");
                //ViewBag.CostSheetId = new SelectList(db.CostSheets, "CostSheetId", "Name");

                return(RedirectToAction("Index"));
                //return RedirectToAction("Details", new { id = costSheetItem.CostSheetId, costSheetItem.ItemId });
            }
            else
            {
                ViewBag.ItemId = new SelectList(db.Items, "ItemId", "ItemPrice");
                //ViewBag.ItemId = new SelectList(db.Items, "ItemId", "UnitCost");
                ViewBag.CostSheetId = new SelectList(db.CostSheets, "CostSheetId", "Name");

                return(View());
            }
        }