Raju Fodse

Raju Fodse

  • 1.5k
  • 244
  • 31.6k

Set Value for Filed on Condition in MVC

Sep 24 2018 1:52 AM
I have three Tables in SQL with following fileds
1) Order : [OrderID (pk)], [OrderSize], [Thickness], [OD] 
2) PipeAllocation : [PipeNo(PK)], [OrderID (fk)], [Length], [Status]
3) Process: [ProcessID (pk)], [PipeNo(fk)], [Date], [MPP]
 
for adding record in process table I want set value for MPP on criteria of Thickness  so I write following code but I got error of "Object reference not set to an instance of an object.". I dont have any null value in thickness field.
 
my code is 
  1. [HttpPost]  
  2.        public ActionResult CreateP3(Process process)  
  3.        {  
  4.            var tr = process.StageID + process.PIPENO + process.Status;  
  5.            var checkme = (from x in db.Processes  
  6.                           where x.StageID + x.PIPENO + x.Status == tr && x.Status == "OK"  
  7.                           select x).ToList();  
  8.            if (checkme.Count > 0)  
  9.            {  
  10.                ModelState.AddModelError("PIPENO""You are trying Duplicate Pipe Entry");  
  11.            }  
  12.            if (ModelState.IsValid)  
  13.            {  
  14.   
  15.                if (process.PipeAl.Order.THK > 1)  
  16.                {  
  17.                    process.MPP = 10;  
  18.                }  
  19.   
  20.                process.CuttingSpeed = (process.ActualMeter*1000)/process.CuttingTime;  
  21.                db.Processes.Add(process);  
  22.                db.SaveChanges();  
  23.                return RedirectToAction("IndexP3");  
  24.            }  
  25.   
  26.            var EmpAtnList = db.Attens.ToList();  
  27.            IEnumerable<SelectListItem> AttnList = from s in EmpAtnList.OrderByDescending(s => s.ATTNDATE)  
  28.                                                   select new SelectListItem  
  29.                                                   {  
  30.                                                       Value = s.ATTNSYSID.ToString(),  
  31.                                                       Text = s.ATTNDATE + "--" + s.Emp.EmpName  
  32.                                                   };  
  33.   
  34.            ViewBag.ATTNSYSID = new SelectList(AttnList, "Value""Text");  
  35.   
  36.            //ViewBag.ATTNSYSID = new SelectList(db.Attens, "ATTNSYSID", "EMPCODE", process.ATTNSYSID);  
  37.            ViewBag.StageID = new SelectList(db.OMStages, "StageID""StageName");  
  38.            ViewBag.NextStageID = new SelectList(db.OMStages.OrderBy(x => x.StageValue), "StageID""StageName");  
  39.            ViewBag.PIPENO = new SelectList(db.PipeAls, "PIPENO""PIPENO");  
  40.            ViewBag.Status = new SelectList(db.ValueAddLists.Where(x => x.RefName == "PipeStatus"), "RefValue""Description", process.Status);  
  41.            return View(process);  
  42.        } 
 

Answers (14)