Exemplo n.º 1
0
        public ActionResult WOLineItemsPartialAddNew(WOLineItem item)
        {
            item.DateCreated = DateTime.Now;
            item.DateUpdated = DateTime.Now;
            var model = db.WOLineItems;


            if (ModelState.IsValid)
            {
                try
                {
                    model.Add(item);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }

            var model1 = from w in db.WOLineItems
                         where w.WorkOrder == item.WorkOrder
                         orderby w.RowOrder
                         select w;

            return(PartialView("_WOLineItemsPartial", model1.ToList()));
        }
Exemplo n.º 2
0
        public ActionResult WOLineItemsPartialUpdate(WOLineItem item)
        {
            // var model = db.WOLineItems;
            // item.DateUpdated = DateTime.Now;
            var model = from w in db.WOLineItems
                        where w.WorkOrder == item.WorkOrder
                        orderby w.RowOrder
                        select w;

            // int? n;
            if (ModelState.IsValid)
            {
                try
                {
                    var modelItem = model.FirstOrDefault(it => it.ID == item.ID);
                    modelItem.DateUpdated = DateTime.Now;
                    //n = Convert.ToInt32(modelItem.WorkOrder);
                    if (modelItem != null)
                    {
                        this.UpdateModel(modelItem);
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }

            //var model1 = from w in db.WOLineItems
            //             where w.WorkOrder == n
            //             orderby w.RowOrder
            //             select w;
            return(PartialView("_WOLineItemsPartial", model.ToList()));
        }