public ActionResult AssertAction(InstrumentAssert instrumentassert) { ModelState.Remove("InstrumentAssertID"); ModelState.Remove("InstrumentCode"); if (ModelState.IsValid) { string msg = ""; if (instrumentassert.InstrumentAssertID > 0) { var dataset = entities.InstrumentAsserts.Where(f => f.InstrumentAssertID == instrumentassert.InstrumentAssertID).FirstOrDefault(); if (dataset != null) { Instrument instument = entities.Instruments.Where(x => x.InstrumentID == instrumentassert.InstrumentID).FirstOrDefault(); String code = "SMMS_" + instument.Name + "_00" + instrumentassert.InstrumentAssertID; dataset.InstrumentCode = code; dataset.InstrumentID = instrumentassert.InstrumentID; dataset.InstrumentConditionID = instrumentassert.InstrumentConditionID; msg = "Instrument Updated Successfully"; } } else { Instrument instument = entities.Instruments.Where(x => x.InstrumentID == instrumentassert.InstrumentID).FirstOrDefault(); try { var insAssert = entities.InstrumentAsserts.Max(x => x.InstrumentAssertID) + 1; String code = "SMMS_" + instument.Name + "_00" + insAssert; instrumentassert.InstrumentCode = code; } catch { String code = "SMMS_" + instument.Name + "_00" + 1; instrumentassert.InstrumentCode = code; } entities.InstrumentAsserts.Add(instrumentassert); msg = "Instrument Added successfully"; } entities.SaveChanges(); return(new JsonResult { Data = new { success = true, action = "Assert", message = msg }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } ViewBag.drpInstrument = CommonController.drpInstrument(); ViewBag.drpInstrumentCondition = CommonController.drpInstrumentCondition(); return(PartialView(instrumentassert)); }
public ActionResult AssertAction(int?id) { ViewBag.drpInstrument = CommonController.drpInstrument(); ViewBag.drpInstrumentCondition = CommonController.drpInstrumentCondition(); if (id != 0) { InstrumentAssert dataset = entities.InstrumentAsserts.Find(id); return(PartialView(dataset)); } else { return(PartialView()); } }