public ActionResult Delete(int id) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; int UserID1 = id; //ViewBag.IsConfigMenu = 0; tblpart tblpart = db.tblparts.Find(id); tblpart.IsDeleted = 1; tblpart.ModifiedBy = UserID1; tblpart.ModifiedOn = System.DateTime.Now; //start Logging int UserID = Convert.ToInt32(Session["UserId"]); String Username = Session["Username"].ToString(); string CompleteModificationdetail = "Deleted Parts/Item"; Action = "Delete"; //ActiveLogStorage Obj = new ActiveLogStorage(); //Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End db.Entry(tblpart).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(tblpart tblpart, int Unit = 0) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); tblpart.CreatedBy = Convert.ToInt32(Session["UserId"]); tblpart.UnitDesc = Unit; tblpart.CreatedOn = DateTime.Now.ToString("yyyyMMddHHmmss"); tblpart.IsDeleted = 0; //ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); string CompleteModificationdetail = "New Creation"; Action = "Create"; //ActiveLogStorage Obj = new ActiveLogStorage(); //Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //End db.tblparts.Add(tblpart); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(int id) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; tblpart tblpart = db.tblparts.Find(id); if (tblpart == null) { return(HttpNotFound()); } ViewBag.unit = new SelectList(db.tblunits.Where(m => m.IsDeleted == 0), "U_ID", "Unit", tblpart.UnitDesc); return(View(tblpart)); }
public ActionResult Edit(tblpart tblpart, int Unit = 0) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; int UserID = Convert.ToInt32(Session["UserId"]); tblpart.UnitDesc = Unit; tblpart.ModifiedBy = UserID; tblpart.ModifiedOn = System.DateTime.Now; { if (ModelState.IsValid) { //#region Active Log Code //tblpart OldData = db.tblparts.Find(tblpart.PartID); //String Username = Session["Username"].ToString(); //IEnumerable<string> FullData = ActiveLog.EnumeratePropertyDifferences<tblpart>(OldData, tblpart); //ICollection<tblpart> c = FullData as ICollection<tblpart>; //int Count = c.Count; //if (Count != 0) //{ // string CompleteModificationdetail = null; // for (int i = 0; i < Count; i++) // { // CompleteModificationdetail = CompleteModificationdetail + "-" + FullData.Take(i).ToArray(); // } // Action = "Edit"; // ActiveLogStorage Obj = new ActiveLogStorage(); // Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); //} //#endregion //End Active Log db.Entry(tblpart).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } ViewBag.unit = new SelectList(db.tblunits.Where(m => m.IsDeleted == 0), "U_ID", "Unit"); return(View(tblpart)); }
public ActionResult Delete(int id) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"].ToString().ToUpper(); ViewBag.roleid = Session["RoleID"]; int UserID = Convert.ToInt32(Session["UserId"]); String Username = Session["Username"].ToString(); tblpart tblmp = db.tblparts.Find(id); tblmp.IsDeleted = 1; tblmp.ModifiedBy = UserID; tblmp.ModifiedOn = DateTime.Now; tblmp.DeletedDate = DateTime.Now; db.Entry(tblmp).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: PartsManagement public ActionResult Index() { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"].ToString().ToUpper(); ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); PartsManagement PM = new PartsManagement(); tblpart mp = new tblpart(); List <tblpart> mplist = new List <tblpart>(); PM.MasterParts = mp; mplist = db.tblparts.Where(m => m.IsDeleted == 0).ToList(); PM.MasterPartsList = mplist; ViewBag.Unit = new SelectList(db.tblunits.Where(p => p.IsDeleted == 0), "U_ID", "UnitDesc"); // ViewData["txtShow"] = ""; //ViewBag.text = ""; return(View(PM)); }
public ActionResult ImportPriorityAlarm(HttpPostedFileBase file) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } //Deleting Excel file #region string fileLocation1 = Server.MapPath("~/Content/"); DirectoryInfo di = new DirectoryInfo(fileLocation1); FileInfo[] files = di.GetFiles("*.xlsx").Where(p => p.Extension == ".xlsx").ToArray(); foreach (FileInfo file1 in files) { try { file1.Attributes = FileAttributes.Normal; System.IO.File.Delete(file1.FullName); } catch { } } #endregion ////start logging //String Username = Session["Username"].ToString(); //int UserID = Convert.ToInt32(Session["UserId"]); //string CompleteModificationdetail = "Import PriorityAlarm"; //Action = "ImportPriorityAlarm"; ////ActiveLogStorage Obj = new ActiveLogStorage(); //Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail); ////End DataSet ds = new DataSet(); if (Request.Files["file"].ContentLength > 0) { string fileExtension = System.IO.Path.GetExtension(Request.Files["file"].FileName); if (fileExtension == ".xls" || fileExtension == ".xlsx") { string fileLocation = Server.MapPath("~/Content/") + Request.Files["file"].FileName; if (System.IO.File.Exists(fileLocation)) { System.IO.File.Delete(fileLocation); } Request.Files["file"].SaveAs(fileLocation); string excelConnectionString = string.Empty; excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; //connection String for xls file format. if (fileExtension == ".xls") { excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\""; } //connection String for xlsx file format. else if (fileExtension == ".xlsx") { excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; } //Create Connection to Excel work book and add oledb namespace OleDbConnection excelConnection = new OleDbConnection(excelConnectionString); excelConnection.Open(); DataTable dt = new DataTable(); dt = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); if (dt == null) { return(null); } String[] excelSheets = new String[dt.Rows.Count]; int t = 0; //excel data saves in temp file here. foreach (DataRow row in dt.Rows) { excelSheets[t] = row["TABLE_NAME"].ToString(); t++; } OleDbConnection excelConnection1 = new OleDbConnection(excelConnectionString); string query = string.Format("Select * from [{0}]", excelSheets[0]); using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, excelConnection1)) { dataAdapter.Fill(ds); } excelConnection.Close(); excelConnection1.Close(); } if (fileExtension.ToString().ToLower().Equals(".xml")) { string fileLocation = Server.MapPath("~/Content/") + Request.Files["FileUpload"].FileName; if (System.IO.File.Exists(fileLocation)) { System.IO.File.Delete(fileLocation); } Request.Files["FileUpload"].SaveAs(fileLocation); XmlTextReader xmlreader = new XmlTextReader(fileLocation); // DataSet ds = new DataSet(); ds.ReadXml(xmlreader); xmlreader.Close(); } if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; string Parts = null; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string a = ds.Tables[0].Rows[i][0].ToString(); if (string.IsNullOrEmpty(a) == false) { int PartNo = 0; //Checking value in db try { PartNo = Convert.ToInt32(ds.Tables[0].Rows[i][0]); } catch { Parts = Parts + " PartNo should be Number.\n"; continue; } // tblpart tblpart = new tblpart(); String Username = Session["Username"].ToString(); tblpart.CreatedBy = Convert.ToInt32(Session["UserId"]); //check if unit is integer(U_ID from tblunits). int unit = 0; try { unit = Convert.ToInt32(ds.Tables[0].Rows[i][4]); } catch { Parts = Parts + "Unit of Part number" + PartNo + " should be Number.\n"; continue; } var msgcode = db.tblunits.Where(m => m.U_ID == unit).SingleOrDefault(); if (msgcode == null) { Parts = Parts + "Unit of Part number " + PartNo + " is not present in DataBase.\n"; continue; } else { tblpart.UnitDesc = Convert.ToInt32(ds.Tables[0].Rows[i][4]); } tblpart.CreatedOn = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); tblpart.IsDeleted = 0; tblpart.PartNo = PartNo; try { tblpart.IdleCycleTime = Convert.ToInt32(ds.Tables[0].Rows[i][3]); } catch { Parts = Parts + "IdleCycleTime of Part Number" + PartNo + " should be Number.\n"; continue; } try { tblpart.PartName = ds.Tables[0].Rows[i][2].ToString(); tblpart.PartDesc = ds.Tables[0].Rows[i][1].ToString(); } catch { Parts = Parts + "PartName or PartDesc " + PartNo + " should not be empty.\n"; continue; } //ActiveLog Code int UserID = Convert.ToInt32(Session["UserId"]); string CompleteModificationdetail = "New Creation"; Action = "Create"; var msgcode1 = db.tblparts.Where(m => m.PartNo == PartNo && m.IsDeleted == 0).SingleOrDefault(); if (msgcode1 == null) { db.tblparts.Add(tblpart); db.SaveChanges(); } else { Parts = Parts + "Part Number " + PartNo + " exists in Database.\n"; continue; } //string dat = DateTime.Now.ToString(); //MsqlConnection mc1 = new MsqlConnection(); //mc1.open(); //MySqlCommand cmd2 = new MySqlCommand("INSERT INTO tblparts(CreatedOn,CreatedBy,IsDeleted, PartDesc, PartName,IdleCycleTime, UnitDesc,PartNo) VALUES" + // "('" + dat + "', " + Convert.ToInt32(Session["UserId"]) + ",0,'" + ds.Tables[0].Rows[i][1].ToString() + "','" + ds.Tables[0].Rows[i][2].ToString() + "'," + // "" + Convert.ToInt32(ds.Tables[0].Rows[i][3]) + ",'" + Convert.ToInt32(ds.Tables[0].Rows[i][4]) + "'," + Convert.ToInt32(ds.Tables[0].Rows[i][0]) + ")", mc1.msqlConnection); //cmd2.ExecuteNonQuery(); //mc1.close(); } } Session["PartNo"] = Parts; } return(RedirectToAction("Index", "Parts")); //return View(); }
//public ActionResult ImportMasterPartsstsw(HttpPostedFileBase file, string UploadType) public ActionResult ImportMasterPartsstsw(HttpPostedFileBase file, string UploadType) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } //Deleting Excel file #region string fileLocation1 = Server.MapPath("~/Content/"); DirectoryInfo di = new DirectoryInfo(fileLocation1); FileInfo[] files = di.GetFiles("*.xlsx").Where(p => p.Extension == ".xlsx").ToArray(); foreach (FileInfo file1 in files) { try { file1.Attributes = FileAttributes.Normal; System.IO.File.Delete(file1.FullName); } catch { } } #endregion DataSet ds = new DataSet(); if (Request.Files["file"].ContentLength > 0) { string fileExtension = System.IO.Path.GetExtension(Request.Files["file"].FileName); if (fileExtension == ".xls" || fileExtension == ".xlsx") { string fileLocation = Server.MapPath("~/Content/") + Request.Files["file"].FileName; if (System.IO.File.Exists(fileLocation)) { System.IO.File.Delete(fileLocation); } Request.Files["file"].SaveAs(fileLocation); string excelConnectionString = string.Empty; excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; //connection String for xls file format. if (fileExtension == ".xls") { excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\""; } //connection String for xlsx file format. else if (fileExtension == ".xlsx") { excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\""; } //Create Connection to Excel work book and add oledb namespace OleDbConnection excelConnection = new OleDbConnection(excelConnectionString); excelConnection.Open(); DataTable dt = new DataTable(); dt = excelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); if (dt == null) { return(null); } String[] excelSheets = new String[dt.Rows.Count]; int t = 0; //excel data saves in temp file here. foreach (DataRow row in dt.Rows) { excelSheets[t] = row["TABLE_NAME"].ToString(); t++; } OleDbConnection excelConnection1 = new OleDbConnection(excelConnectionString); string query = string.Format("Select * from [{0}]", excelSheets[0]); using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, excelConnection1)) { dataAdapter.Fill(ds); } excelConnection.Close(); excelConnection1.Close(); } if (fileExtension.ToString().ToLower().Equals(".xml")) { string fileLocation = Server.MapPath("~/Content/") + Request.Files["FileUpload"].FileName; if (System.IO.File.Exists(fileLocation)) { System.IO.File.Delete(fileLocation); } Request.Files["FileUpload"].SaveAs(fileLocation); XmlTextReader xmlreader = new XmlTextReader(fileLocation); // DataSet ds = new DataSet(); ds.ReadXml(xmlreader); xmlreader.Close(); } if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"].ToString().ToUpper(); ViewBag.roleid = Session["RoleID"]; var unitsItem = db.tblunits.Where(m => m.IsDeleted == 0).ToList(); List <string> TimeUnits = new List <string>(); foreach (var item in unitsItem) { TimeUnits.Add(item.Unit.ToString()); } string text = ""; string ErrorMsg = null; if (UploadType == "OverWrite") // Accept only New Codes { #region for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tblpart tblmp = new tblpart(); String Username = Session["Username"].ToString(); tblmp.CreatedBy = Convert.ToInt32(Session["UserId"]); tblmp.CreatedOn = DateTime.Now; tblmp.IsDeleted = 0; string PartName = null, OperationNo = null; PartName = Convert.ToString(ds.Tables[0].Rows[i][0]); OperationNo = Convert.ToString(ds.Tables[0].Rows[i][1]); using (i_facility_unimechEntities db1 = new i_facility_unimechEntities()) { var MasterStdPWTData = db1.tblparts.Where(m => m.FGCode == PartName && m.OperationNo == OperationNo).FirstOrDefault(); if (MasterStdPWTData != null) { try { try { string unitDesc = Convert.ToString(ds.Tables[0].Rows[i][4]); if (TimeUnits.Contains(unitDesc)) { int?unitId = db.tblunits.Where(m => m.Unit == unitDesc).Select(m => m.U_ID).FirstOrDefault(); MasterStdPWTData.UnitDesc = Convert.ToInt32(unitId); } else //Default Unit { MasterStdPWTData.UnitDesc = 1; } } catch { text = text + htmlerrorMaker(PartName, OperationNo, "Please check with Unit"); continue; } //ErrorMsg = ErrorMsg + PartName + " and " + OperationNo + " has details in Database.\n"; try { MasterStdPWTData.IdealCycleTime = Convert.ToDecimal(ds.Tables[0].Rows[i][2]); } catch { text = text + htmlerrorMaker(PartName, OperationNo, "Please check with Std Cycle Time"); continue; } try { MasterStdPWTData.StdMinorLoss = Convert.ToString(ds.Tables[0].Rows[i][3]); } catch { text = text + htmlerrorMaker(PartName, OperationNo, "Please check with Std Minor Loss"); continue; } MasterStdPWTData.ModifiedOn = DateTime.Now; MasterStdPWTData.ModifiedBy = Convert.ToInt32(Session["UserId"]); //db.Entry(MasterStdPWTData).State = System.Data.Entity.EntityState.Modified; db1.SaveChanges(); continue; } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } //throw; } } else if (string.IsNullOrEmpty(PartName) || string.IsNullOrEmpty(OperationNo)) { text = text + htmlerrorMaker(PartName, OperationNo, "PartName or OperationNo cannot be empty"); //ErrorMsg += " PartName or OperationNo cannot be empty for " + PartName + " and " + OperationNo + " .\n"; continue; } else { tblmp.FGCode = PartName; tblmp.OperationNo = OperationNo; } } try { string unitDesc = Convert.ToString(ds.Tables[0].Rows[i][4]); if (TimeUnits.Contains(unitDesc)) { int?unitId = db.tblunits.Where(m => m.Unit == unitDesc).Select(m => m.U_ID).FirstOrDefault(); tblmp.UnitDesc = Convert.ToInt32(unitId); } else //Default Unit { tblmp.UnitDesc = 1; } } catch { text = text + htmlerrorMaker(PartName, OperationNo, "Please check with Unit"); continue; } try { tblmp.IdealCycleTime = Convert.ToDecimal(ds.Tables[0].Rows[i][2]); } catch { text = text + htmlerrorMaker(PartName, OperationNo, "Please check with IdealCycleTime "); continue; } try { tblmp.StdMinorLoss = Convert.ToString(ds.Tables[0].Rows[i][3]); } catch { text = text + htmlerrorMaker(PartName, OperationNo, "Please check with Std Minor Loss"); continue; } db.tblparts.Add(tblmp); db.SaveChanges(); } #endregion } else if (UploadType == "New") // Delete Duplicate and Insert New. // if not Duplicate insert that { #region for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tblpart tblmp = new tblpart(); String Username = Session["Username"].ToString(); tblmp.CreatedBy = Convert.ToInt32(Session["UserId"]); tblmp.CreatedOn = DateTime.Now; tblmp.IsDeleted = 0; string PartName = null, OperationNo = null; PartName = Convert.ToString(ds.Tables[0].Rows[i][0]); OperationNo = Convert.ToString(ds.Tables[0].Rows[i][1]); bool check = ValidationCheckForInsertion(PartName, OperationNo); if (check == true) { using (i_facility_unimechEntities db1 = new i_facility_unimechEntities()) { try { if (string.IsNullOrEmpty(PartName) || string.IsNullOrEmpty(OperationNo)) { text = text + htmlerrorMaker(PartName, OperationNo, "PartName or OperationNo cannot be empty"); continue; } else { tblmp.FGCode = PartName; tblmp.OperationNo = OperationNo; } try { string unitDesc = Convert.ToString(ds.Tables[0].Rows[i][4]); if (TimeUnits.Contains(unitDesc)) { int?unitId = db.tblunits.Where(m => m.Unit == unitDesc).Select(m => m.U_ID).FirstOrDefault(); tblmp.UnitDesc = Convert.ToInt32(unitId); } else //Default Unit { tblmp.UnitDesc = 1; } } catch { text = text + htmlerrorMaker(PartName, OperationNo, "Please check with Unit"); continue; } try { tblmp.IdealCycleTime = Convert.ToDecimal(ds.Tables[0].Rows[i][2]); } catch { text = text + htmlerrorMaker(PartName, OperationNo, "Please check with IdealCycleTime "); continue; } try { tblmp.StdMinorLoss = Convert.ToString(ds.Tables[0].Rows[i][3]); } catch { text = text + htmlerrorMaker(PartName, OperationNo, "Please check with Std Minor Loss"); continue; } //check for dup and delete previous one. var Dupdata = db.tblparts.Where(m => m.FGCode == PartName && m.OperationNo == OperationNo && m.IsDeleted == 0).FirstOrDefault(); if (Dupdata != null) { Dupdata.IsDeleted = 1; Dupdata.DeletedDate = DateTime.Now; //db.Entry(Dupdata).State = System.Data.Entity.EntityState.Modified; db1.SaveChanges(); } db1.tblparts.Add(tblmp); db1.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } //throw; } } } } #endregion } else if (UploadType == "Update") // OverWrite Existing Values { #region for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { tblpart tblmp = new tblpart(); String Username = Session["Username"].ToString(); tblmp.CreatedBy = Convert.ToInt32(Session["UserId"]); tblmp.CreatedOn = DateTime.Now; tblmp.IsDeleted = 0; string PartName = null, OperationNo = null; PartName = Convert.ToString(ds.Tables[0].Rows[i][0]); OperationNo = Convert.ToString(ds.Tables[0].Rows[i][1]); DateTime createdOn = DateTime.Now; if (string.IsNullOrEmpty(PartName) || string.IsNullOrEmpty(OperationNo)) { text = text + htmlerrorMaker(PartName, OperationNo, "PartName or OperationNo cannot be empty"); continue; } else { tblmp.FGCode = PartName; tblmp.OperationNo = OperationNo; } try { string unitDesc = Convert.ToString(ds.Tables[0].Rows[i][4]); if (TimeUnits.Contains(unitDesc)) { int?unitId = db.tblunits.Where(m => m.Unit == unitDesc).Select(m => m.U_ID).FirstOrDefault(); tblmp.UnitDesc = Convert.ToInt32(unitId); } else //Default Unit { tblmp.UnitDesc = 1; } } catch { text = text + htmlerrorMaker(PartName, OperationNo, "Please check with Unit"); continue; } try { tblmp.IdealCycleTime = Convert.ToDecimal(ds.Tables[0].Rows[i][2]); } catch { text = text + htmlerrorMaker(PartName, OperationNo, "Please check with IdealCycleTime "); continue; } try { tblmp.StdMinorLoss = Convert.ToString(ds.Tables[0].Rows[i][3]); } catch { text = text + htmlerrorMaker(PartName, OperationNo, "Please check with Std Minor Loss"); continue; } var MasterStdPWTData = db.tblparts.Where(m => m.FGCode == PartName && m.OperationNo == OperationNo && m.IsDeleted == 0).FirstOrDefault(); if (MasterStdPWTData == null) { db.tblparts.Add(tblmp); db.SaveChanges(); } else { MasterStdPWTData.ModifiedBy = Convert.ToInt32(Session["UserId"]); MasterStdPWTData.ModifiedOn = DateTime.Now; MasterStdPWTData.IsDeleted = 1; MasterStdPWTData.DeletedDate = DateTime.Now; db.Entry(MasterStdPWTData).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); db.tblparts.Add(tblmp); db.SaveChanges(); } } #endregion } TempData["txtShow"] = text; // ViewBag.text = text; Session["FGCode"] = ErrorMsg; } //return RedirectToAction("Index", "MasterParts"); return(RedirectToAction("Index", "PartsManagement")); }