public ActionResult Edit(tblmachineallocation tblmachine) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } string CorrectedDate = null; tbldaytiming StartTime = db.tbldaytimings.Where(m => m.IsDeleted == 0).SingleOrDefault(); TimeSpan Start = StartTime.StartTime; if (Start <= DateTime.Now.TimeOfDay) { CorrectedDate = DateTime.Now.ToString("yyyy-MM-dd"); } else { CorrectedDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); } tblmachine.CorrectedDate = CorrectedDate; tblmachine.ModifiedBy = Convert.ToInt32(Session["UserId"]); tblmachine.ModifiedOn = DateTime.Now; tblmachine.IsDeleted = 0; if (ModelState.IsValid) { db.Entry(tblmachine).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserID = new SelectList(db.tblusers.Where(m => m.IsDeleted == 0 && m.PrimaryRole == 3), "UserID", "DisplayName", tblmachine.UserID); // ViewBag.ShiftID = new SelectList(db.tblshiftdetails_machinewise.Where(m => m.IsDeleted == 0).GroupBy(m => m.ShiftDetailsID), "ShiftDetailsID", "ShiftName"); ViewBag.MachineID = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0), "MachineID", "MachineDispName", tblmachine.MachineID); return(View(tblmachine)); }
public ActionResult Edit(recipientmailid tblrm) { 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(); int UserID = Convert.ToInt32(Session["UserId"]); tblrm.ModifiedBy = UserID; tblrm.ModifiedOn = System.DateTime.Now; ViewBag.AutoEmailType = new SelectList(db.tblemailreporttypes.Where(m => m.IsDeleted == 0), "ERTID", "ReportType"); //#region Active Log Code //recipientmailid OldData = db.recipientmailids.Find(tblrm.RE_ID); //IEnumerable<string> FullData = ActiveLog.EnumeratePropertyDifferences<recipientmailid>(OldData, tblrm); //ICollection<recipientmailid> c = FullData as ICollection<recipientmailid>; //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(tblrm).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(message_code_master msgcm) { 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(); int UserID = Convert.ToInt32(Session["UserID"]); msgcm.ModifiedBy = UserID.ToString(); msgcm.ModifiedOn = System.DateTime.Now; msgcm.MessageType = "BREAKDOWN"; var msgcode = db.message_code_master.Where(m => m.MessageCode == msgcm.MessageCode && m.MessageCode != msgcm.MessageCode).SingleOrDefault(); if (msgcode == null) { db.Entry(msgcm).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BDCode = "This Code is in Use"; return(View(msgcm)); }
public ActionResult Edit(tblmachinedetail tblmachine, int Shop = 0, int Plant = 0, int Cell = 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"]); tblmachine.ModifiedBy = UserID; tblmachine.ModifiedOn = System.DateTime.Now; { if (ModelState.IsValid) { #region Active Log Code //tblmachinedetail OldData = db.tblmachinedetails.Find(tblmachine.MachineID); //String Username = Session["Username"].ToString(); //IEnumerable<string> FullData = ActiveLog.EnumeratePropertyDifferences<tblmachinedetail>(OldData, tblmachine); //ICollection<tblmachinedetail> c = FullData as ICollection<tblmachinedetail>; //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 var shopname = db.tblshops.Where(m => m.IsDeleted == 0 && m.ShopID == tblmachine.ShopID).Select(m => m.ShopName).FirstOrDefault(); tblmachine.ShopNo = shopname.ToString(); //tblmachine.PlantID = Plant; //tblmachine.ShopID = Shop; //if (Cell != 0) //{ // tblmachine.CellID = Cell; //} db.Entry(tblmachine).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } ViewBag.Plant = new SelectList(db.tblplants.Where(m => m.IsDeleted == 0), "PlantID", "PlantName", tblmachine.PlantID); ViewBag.Shop = new SelectList(db.tblshops.Where(m => m.IsDeleted == 0 && m.PlantID == tblmachine.PlantID), "ShopID", "ShopName", tblmachine.ShopID); ViewBag.Cell = new SelectList(db.tblcells.Where(m => m.IsDeleted == 0 && m.ShopID == tblmachine.ShopID), "CellID", "CellName", tblmachine.CellID); ViewBag.WC = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0 && m.ShopID == tblmachine.ShopID && m.CellID == tblmachine.CellID), "MachineInvNo", "MachineInvNo", tblmachine.MachineInvNo); return(View(tblmachine)); }
public ActionResult Edit(tbluser tbluser) { 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(); int UserID = Convert.ToInt32(Session["UserID"]); int roleid = Convert.ToInt32(Session["RoleID"]); tbluser.ModifiedBy = UserID; tbluser.ModifiedOn = System.DateTime.Now; var dupUserData = db.tblusers.Where(m => m.IsDeleted == 0 && m.UserName == tbluser.UserName && m.UserID != tbluser.UserID).ToList(); if (dupUserData.Count == 0) { #region Active Log Code //tblUser OldData = db.tblUsers.Find(tbluser.UserID); //IEnumerable<string> FullData = ActiveLog.EnumeratePropertyDifferences<tblUser>(OldData, tbluser); //ICollection<tblUser> c = FullData as ICollection<tblUser>; //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 int primaryrole = Convert.ToInt32(tbluser.PrimaryRole); if (primaryrole != 3) { tbluser.MachineID = Convert.ToInt32(System.DBNull.Value); } db.Entry(tbluser).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { Session["Error"] = "User Name Exists."; ViewBag.PrimaryRole = new SelectList(db.tblroles.Where(m => m.IsDeleted == 0 && m.Role_ID >= roleid), "Role_ID", "RoleDesc", tbluser.PrimaryRole); ViewBag.SecondaryRole = new SelectList(db.tblroles.Where(m => m.IsDeleted == 0 && m.Role_ID >= roleid), "Role_ID", "RoleDesc", tbluser.SecondaryRole); ViewBag.MachineID = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0), "MachineID", "MachineDispName", tbluser.MachineID); return(View(tbluser)); } }
public ActionResult Edit(tblmodulemaster tblModule) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; if (Request.Cookies["YourApLogin&"] != null) { string username = Request.Cookies["YourAppLogin"].Values["username"]; string RoleID = Request.Cookies["YourAppLogin"].Values["RoleID"]; string UserID = Request.Cookies["YourAppLogin"].Values["UserId"]; Session["Username"] = username; Session["RoleID"] = RoleID; Session["UserId"] = UserID; } else if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } else { ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); } int UserID1 = Convert.ToInt32(Session["UserID"].ToString()); ViewBag.IsEmailEscalation = 0; tblModule.ModifiedBy = UserID1; string moduleName = tblModule.ModuleName; tblModule.ModifiedOn = System.DateTime.Now; { if (ModelState.IsValid) { db.Entry(tblModule).State = EntityState.Modified; db.SaveChanges(); //Updating in module helper int ID = Convert.ToInt32(Session["ID"]); tblmodulehelper module = db.tblmodulehelpers.Find(ID); module.ModuleID = moduleName; db.Entry(tblModule).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(tblModule)); }
public ActionResult Edit(tblcell tblmc, int Shop = 0, int Plant = 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(); int UserID = Convert.ToInt32(Session["UserID"]); //Cell name validation string cellname = tblmc.CellName.ToString(); int cellid = tblmc.CellID; var doesThisShopExists = db.tblcells.Where(m => m.IsDeleted == 0 && m.PlantID == Plant && m.ShopID == Shop && m.CellName == cellname && m.CellID != cellid).ToList(); if (doesThisShopExists.Count == 0) { #region Active Log Code //tblmachinecategory OldData = db.tblmachinecategories.Find(tblmc.ID); //IEnumerable<string> FullData = ActiveLog.EnumeratePropertyDifferences<tblmachinecategory>(OldData, tblmc); //ICollection<tblmachinecategory> c = FullData as ICollection<tblmachinecategory>; //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 tblmc.PlantID = Plant; tblmc.ShopID = Shop; tblmc.ModifiedBy = UserID; tblmc.ModifiedOn = DateTime.Now; db.Entry(tblmc).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.Plant = new SelectList(db.tblplants.Where(m => m.IsDeleted == 0), "PlantID", "PlantName", tblmc.PlantID); ViewBag.Shop = new SelectList(db.tblshops.Where(m => m.IsDeleted == 0), "ShopID", "ShopName", tblmc.ShopID); Session["Error"] = "Cell Name already exists for this Shop."; return(View(tblmc)); } }
public ActionResult Edit(tblcustomer tblCustomer, HttpPostedFileBase inputimg) { if (Request.Cookies["YourApLogin&"] != null) { string username = Request.Cookies["YourAppLogin"].Values["username"]; string RoleID = Request.Cookies["YourAppLogin"].Values["RoleID"]; string UserID = Request.Cookies["YourAppLogin"].Values["UserId"]; Session["Username"] = username; Session["RoleID"] = RoleID; Session["UserId"] = UserID; } else if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } else { ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); } int UserID1 = Convert.ToInt32(Session["UserID"].ToString()); ViewBag.IsEmailEscalation = 0; //tblCustomer.Logo = inputimg; tblCustomer.ModifiedBy = UserID1; tblCustomer.ModifiedOn = System.DateTime.Now; { if (ModelState.IsValid) { if (inputimg == null) { //byte b =Convert.ToByte(Session["logo"]);// img src //byte[] imgarray = new byte[b]; //= (Session["logo"]).ToString(); //tblCustomer.Logo = Encoding.ASCII.GetBytes(a); var a = Session["logo"] as byte[]; tblCustomer.Logo = a; } tblCustomer.IsDeleted = 0; db.Entry(tblCustomer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(tblCustomer)); }
public ActionResult Edit(IEnumerable <tblroleplaymaster> tblrolePlay) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; if (Request.Cookies["YourApLogin&"] != null) { string username = Request.Cookies["YourAppLogin"].Values["username"]; string RoleID = Request.Cookies["YourAppLogin"].Values["RoleID"]; string UserID = Request.Cookies["YourAppLogin"].Values["UserId"]; Session["Username"] = username; Session["RoleID"] = RoleID; Session["UserId"] = UserID; } else if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } else { ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; String Username = Session["Username"].ToString(); } int UserID1 = Convert.ToInt32(Session["UserID"].ToString()); if (tblrolePlay != null) { if (ModelState.IsValid) { foreach (var plan in tblrolePlay) { plan.tblmodulemaster = null; //plan.tblrole = null; plan.ModifiedBy = Convert.ToInt32(Session["UserID"]); plan.ModifiedOn = System.DateTime.Now; db.Entry(plan).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); } } return(View(tblrolePlay)); }
public ActionResult Edit(message_code_master msgcm) { 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(); int UserID = Convert.ToInt32(Session["UserID"]); msgcm.ModifiedBy = UserID.ToString(); msgcm.ModifiedOn = System.DateTime.Now; msgcm.MessageType = "IDLE"; if (ModelState.IsValid) { //#region Active Log Code //tblrole OldData = db.tblroles.Find(tblrole.Role_ID); //IEnumerable<string> FullData = ActiveLog.EnumeratePropertyDifferences<tblrole>(OldData, tblrole); //ICollection<tblrole> c = FullData as ICollection<tblrole>; //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 var msgcode = db.message_code_master.Where(m => m.MessageCode == msgcm.MessageCode && m.MessageCode != msgcm.MessageCode).SingleOrDefault(); if (msgcode == null) { db.Entry(msgcm).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BDCode = "This Code is in Use"; ViewBag.MessageType = new SelectList(db.tbldowntimecategories.Where(m => m.IsDeleted == 0), "DTCategory", "DTCategory"); return(View(msgcm)); } return(View(msgcm)); }
public ActionResult Edit(tblpriorityalarm tblpriorityalarm) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; //Section related to storing data in ActiveLog String Username = Session["Username"].ToString(); int UserID = Convert.ToInt32(Session["UserId"]); //#region Active Log Code //tblpriorityalarm OldData = db.tblpriorityalarms.Find(tblpriorityalarm.AlarmID); //IEnumerable<string> FullData = ActiveLog.EnumeratePropertyDifferences<tblpriorityalarm>(OldData, tblpriorityalarm); //ICollection<tblpriorityalarm> c = FullData as ICollection<tblpriorityalarm>; //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 if (ModelState.IsValid) { DateTime modifiedOn = DateTime.Now; tblpriorityalarm.ModifiedBy = UserID; tblpriorityalarm.ModifiedOn = modifiedOn; db.Entry(tblpriorityalarm).State = EntityState.Modified; db.SaveChanges(); //db.updateAlarmsPrority(tblpriorityalarm.AlarmID, tblpriorityalarm.AlarmNumber, tblpriorityalarm.AlarmDesc, tblpriorityalarm.AxisNo, tblpriorityalarm.AlarmGroup, tblpriorityalarm.PriorityNumber, 0, tblpriorityalarm.CreatedOn, tblpriorityalarm.CreatedBy, modifiedOn, 1); return(RedirectToAction("Index")); } ViewBag.MachineID = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0), "MachineID", "MachineDispName"); return(View(tblpriorityalarm)); }
public ActionResult Edit(tblshift_mstr tblshift_mstr) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } tblshift_mstr.ModifiedBy = 1; tblshift_mstr.ModifiedOn = DateTime.Now; tblshift_mstr.IsDeleted = 0; if (ModelState.IsValid) { db.Entry(tblshift_mstr).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblshift_mstr)); }
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 = 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(); tbloperatordetail OpTDet = db.tbloperatordetails.Find(id); OpTDet.isDeleted = 1; OpTDet.ModifiedBy = UserID; OpTDet.ModifiedOn = DateTime.Now; db.Entry(OpTDet).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(tbldowntimecategory tbldowntimecategory) { 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"]); String Username = Session["Username"].ToString(); if (ModelState.IsValid) { //#region Active Log Code //tbldowntimecategory OldData = db.tbldowntimecategories.Find(tbldowntimecategory.DTC_ID); //IEnumerable<string> FullData = ActiveLog.EnumeratePropertyDifferences<tbldowntimecategory>(OldData, tbldowntimecategory); //ICollection<tbldowntimecategory> c = FullData as ICollection<tbldowntimecategory>; //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 DateTime TimeOFCreation = DateTime.Now; tbldowntimecategory.ModifiedBy = UserID; tbldowntimecategory.ModifiedOn = TimeOFCreation; db.Entry(tbldowntimecategory).State = EntityState.Modified; db.SaveChanges(); DateTime Date = DateTime.Now; //db.updateDownTimeCategory(tbldowntimecategory.DTC_ID, tbldowntimecategory.DTCategory, tbldowntimecategory.DTCategoryDesc, tbldowntimecategory.IsDeleted, tbldowntimecategory.CreatedOn, 1, Date,1); return(RedirectToAction("Index")); } return(View(tbldowntimecategory)); }
public ActionResult Edit(tblplannedbreak tblplannedbreak) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; tblplannedbreak.ModifiedBy = 1; tblplannedbreak.ModifiedOn = DateTime.Now; tblplannedbreak.IsDeleted = 0; //if (ModelState.IsValid) { db.Entry(tblplannedbreak).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblplannedbreak)); }
public ActionResult Edit(tblmasterparts_st_sw tblmp) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; //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 string partno = tblmp.PartNo; string opno = tblmp.OpNo; int mpid = tblmp.PARTSSTSWID; var partInMP = db.tblmasterparts_st_sw.Where(m => m.IsDeleted == 0 && (m.PartNo == partno && m.OpNo == opno) && m.PARTSSTSWID != mpid).ToList(); if (partInMP.Count > 0) { Session["Error"] = "PartNo " + partno + " has details in Database"; return(View(tblmp)); } tblmp.CreatedOn = DateTime.Now; tblmp.CreatedBy = UserID; tblmp.IsDeleted = 0; db.Entry(tblmp).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(IEnumerable <tblshiftdetail> tblp, int ShiftMethod = 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(); #region//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 #endregion //shop name validation //string shopname = tblp.ShopName.ToString(); //var doesThisShiftDetailsExists = db.tblshiftdetails.Where(m => m.IsDeleted == 0 && m.ShiftDetailsName == ).ToList(); //if (doesThisShopExists.Count == 0) //{ //check if there's a entry of this shiftMethod in tblshiftdetails var shiftmethodCheck = db.tblshiftdetails.Where(m => m.IsDeleted == 0 && m.ShiftMethodID == ShiftMethod).ToList(); if (shiftmethodCheck.Count > 0) { Session["Error"] = "ShiftDetails for this ShiftMethod Exists."; ViewBag.ShiftMethod = new SelectList(db.tblshiftmethods.Where(m => m.IsDeleted == 0), "ShiftMethodID", "ShiftMethodName"); return(RedirectToAction("Index")); } var shiftmethodiddata = db.tblshiftmethods.Where(m => m.IsDeleted == 0 && m.ShiftMethodID == ShiftMethod).SingleOrDefault(); int noofshifts = shiftmethodiddata.NoOfShifts; int rowscount = 0; //to check if names are duplicate List <string> shiftdetailsnames = new List <string>(); foreach (var shift in tblp) { if (shift.ShiftDetailsName != null) { shiftdetailsnames.Add(shift.ShiftDetailsName); } } // for current shiftdetails. if (shiftdetailsnames.Distinct().Count() != shiftdetailsnames.Count()) { //Console.WriteLine("List contains duplicate values."); TempData["Error"] = "Shift Names Cannot be Same."; ViewBag.ShiftMethod = new SelectList(db.tblshiftmethods.Where(m => m.IsDeleted == 0), "ShiftMethodID", "ShiftMethodName"); return(RedirectToAction("Index")); } try { foreach (var shift in tblp) { if (rowscount < noofshifts) { // calculate duration int duration = 0; string starttimestring = "2016-06-02" + " " + shift.ShiftStartTime; DateTime starttimedatetime = Convert.ToDateTime(starttimestring); string endtimestring = null; TimeSpan tsStart = (System.TimeSpan)shift.ShiftStartTime; TimeSpan tsEnd = (System.TimeSpan)shift.ShiftEndTime; int result = TimeSpan.Compare(tsStart, tsEnd); if (result < 0) { endtimestring = "2016-06-02" + " " + shift.ShiftEndTime; } else if (result > 0) { endtimestring = "2016-06-03" + " " + shift.ShiftEndTime; shift.NextDay = 1; } DateTime endtimedatetime = Convert.ToDateTime(endtimestring); TimeSpan ts = endtimedatetime.Subtract(starttimedatetime); duration = Convert.ToInt32(ts.TotalMinutes); //create new object/row tblshiftdetail tsd = new tblshiftdetail(); tsd.CreatedBy = UserID; tsd.CreatedOn = DateTime.Now; tsd.Duration = duration; tsd.IsDeleted = 0; tsd.NextDay = shift.NextDay; tsd.ShiftMethodID = ShiftMethod; tsd.ShiftDetailsDesc = shift.ShiftDetailsDesc; tsd.ShiftDetailsName = shift.ShiftDetailsName; tsd.ShiftEndTime = shift.ShiftEndTime; tsd.ShiftStartTime = shift.ShiftStartTime; db.tblshiftdetails.Add(tsd); db.SaveChanges(); } rowscount++; } } catch (Exception e) { Session["Error"] = "Shift Name already exists for this ShiftMethod."; using (i_facility_tamlEntities db1 = new i_facility_tamlEntities()) { var todeletedata = db1.tblshiftdetails.Where(m => m.IsDeleted == 0 && m.ShiftMethodID == ShiftMethod).ToList(); foreach (var row in todeletedata) { row.IsDeleted = 1; db.Entry(row).State = EntityState.Modified; db.SaveChanges(); } } } //ViewBag.ShiftMethod = new SelectList(db.tblshiftmethods.Where(m => m.IsDeleted == 0), "ShiftMethodID", "ShiftMethodName"); return(RedirectToAction("Index")); }
public ActionResult Create(tbllossescode tlc, int Level1 = 0, int Level2 = 0) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } int UserID = Convert.ToInt32(Session["UserId"]); ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; tlc.CreatedBy = UserID; tlc.CreatedOn = DateTime.Now; tlc.IsDeleted = 0; tlc.MessageType = "BREAKDOWN"; if (Convert.ToInt16(tlc.LossCodesLevel) == 2) { tlc.LossCodesLevel1ID = Level1; var duplosscode = db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCode == tlc.LossCode && m.LossCodesLevel1ID == tlc.LossCodesLevel1ID).ToList(); if (duplosscode.Count() == 0) { //Here check if Level1 code is used in tbllossofentry, if so then create new copy of it with Different LossID. var lossOfEntryData = db.tbllossofentries.Where(m => m.MessageCodeID == Level1).ToList(); if (lossOfEntryData.Count() > 0) { var lossPrvData = db.tbllossescodes.Where(m => m.LossCodeID == Level1 && m.IsDeleted == 0).FirstOrDefault(); tbllossescode tlcNewPrvLevel = new tbllossescode(); tlcNewPrvLevel.ContributeTo = lossPrvData.ContributeTo; tlcNewPrvLevel.CreatedBy = lossPrvData.CreatedBy; tlcNewPrvLevel.CreatedOn = lossPrvData.CreatedOn; tlcNewPrvLevel.IsDeleted = 0; tlcNewPrvLevel.LossCode = lossPrvData.LossCode; tlcNewPrvLevel.LossCodeDesc = lossPrvData.LossCodeDesc; tlcNewPrvLevel.LossCodesLevel = lossPrvData.LossCodesLevel; tlcNewPrvLevel.LossCodesLevel1ID = lossPrvData.LossCodesLevel1ID; tlcNewPrvLevel.LossCodesLevel2ID = lossPrvData.LossCodesLevel2ID; tlcNewPrvLevel.MessageType = lossPrvData.MessageType; tlcNewPrvLevel.ModifiedBy = lossPrvData.ModifiedBy; tlcNewPrvLevel.ModifiedOn = lossPrvData.ModifiedOn; db.tbllossescodes.Add(tlcNewPrvLevel); db.SaveChanges(); //Delete the Old one. lossPrvData.IsDeleted = 1; lossPrvData.ModifiedOn = DateTime.Now; lossPrvData.ModifiedBy = UserID; db.Entry(lossPrvData).State = EntityState.Modified; db.SaveChanges(); //Give new Level1 LossCodeID to 2nd level code. int Level1LossCodeID = tlcNewPrvLevel.LossCodeID; tlc.LossCodesLevel1ID = Level1LossCodeID; } db.tbllossescodes.Add(tlc); db.SaveChanges(); return(RedirectToAction("Index")); } else { Session["Error"] = "Breakdown code already Exist."; ViewData["Level1"] = new SelectList(db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCodesLevel == 1 && m.MessageType == "BREAKDOWN" && m.LossCodeID != 9999), "LossCodeID", "LossCode"); ViewData["Level2"] = new SelectList(db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCodesLevel == 2 && m.MessageType == "BREAKDOWN"), "LossCodeID", "LossCode"); return(View(tlc)); } } if (Convert.ToInt16(tlc.LossCodesLevel) == 3) { tlc.LossCodesLevel1ID = Level1; tlc.LossCodesLevel2ID = Level2; var duplosscode = db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCode == tlc.LossCode && m.LossCodesLevel1ID == tlc.LossCodesLevel1ID && m.LossCodesLevel2ID == tlc.LossCodesLevel2ID).ToList(); if (duplosscode.Count() == 0) { //Here check if Level1 code is used in tbllossofentry, if so then create new copy of it with Different LossID. var lossOfEntryData = db.tbllossofentries.Where(m => m.MessageCodeID == Level2).ToList(); if (lossOfEntryData.Count() > 0) { var lossPrvData = db.tbllossescodes.Where(m => m.LossCodeID == Level2 && m.IsDeleted == 0).FirstOrDefault(); tbllossescode tlcNewPrvLevel = new tbllossescode(); tlcNewPrvLevel.ContributeTo = lossPrvData.ContributeTo; tlcNewPrvLevel.CreatedBy = lossPrvData.CreatedBy; tlcNewPrvLevel.CreatedOn = lossPrvData.CreatedOn; tlcNewPrvLevel.IsDeleted = 0; tlcNewPrvLevel.LossCode = lossPrvData.LossCode; tlcNewPrvLevel.LossCodeDesc = lossPrvData.LossCodeDesc; tlcNewPrvLevel.LossCodesLevel = lossPrvData.LossCodesLevel; tlcNewPrvLevel.LossCodesLevel1ID = lossPrvData.LossCodesLevel1ID; tlcNewPrvLevel.LossCodesLevel2ID = lossPrvData.LossCodesLevel2ID; tlcNewPrvLevel.MessageType = lossPrvData.MessageType; tlcNewPrvLevel.ModifiedBy = lossPrvData.ModifiedBy; tlcNewPrvLevel.ModifiedOn = lossPrvData.ModifiedOn; db.tbllossescodes.Add(tlcNewPrvLevel); db.SaveChanges(); //Delete the Old one. lossPrvData.IsDeleted = 1; lossPrvData.ModifiedOn = DateTime.Now; lossPrvData.ModifiedBy = UserID; db.Entry(lossPrvData).State = EntityState.Modified; db.SaveChanges(); //Give new Level1 LossCodeID to 2nd level code. int Level2LossCodeID = tlcNewPrvLevel.LossCodeID; tlc.LossCodesLevel2ID = Level2LossCodeID; } db.tbllossescodes.Add(tlc); db.SaveChanges(); return(RedirectToAction("Index")); } else { Session["Error"] = "Breakdown code already Exist."; ViewData["Level1"] = new SelectList(db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCodesLevel == 1 && m.MessageType == "BREAKDOWN" && m.LossCodeID != 9999), "LossCodeID", "LossCode"); ViewData["Level2"] = new SelectList(db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCodesLevel == 2 && m.MessageType == "BREAKDOWN"), "LossCodeID", "LossCode"); return(View(tlc)); } } if (Convert.ToInt16(tlc.LossCodesLevel) == 1) { var duplosscode = db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCode == tlc.LossCode).ToList(); if (duplosscode.Count() == 0) { db.tbllossescodes.Add(tlc); db.SaveChanges(); return(RedirectToAction("Index")); } else { Session["Error"] = "Breakdown code already Exist."; ViewData["Level1"] = new SelectList(db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCodesLevel == 1 && m.MessageType == "BREAKDOWN" && m.LossCodeID != 9999), "LossCodeID", "LossCode"); ViewData["Level2"] = new SelectList(db.tbllossescodes.Where(m => m.IsDeleted == 0 && m.LossCodesLevel == 2 && m.MessageType == "BREAKDOWN"), "LossCodeID", "LossCode"); return(View(tlc)); } } return(RedirectToAction("Index")); }
public ActionResult Edit(tbl_autoreportsetting tee) { 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(); #region//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 #endregion //Email validation string RL1 = Convert.ToString(tee.ReportID); string RL2 = Convert.ToString(tee.BasedOn); string RL3 = Convert.ToString(tee.AutoReportTimeID); string ValidEscalation = null; //ValidEscalation = IsItValidEscalation(RL1, RL2, RL3); if (tee.AutoReportTimeID == 1) //day { tee.NextRunDate = Convert.ToDateTime("2018-12-27 17:35:00"); //tee.NextRunDate = DateTime.Now.AddDays(1); } else if (tee.AutoReportTimeID == 2) //week { DateTime begining, end; GetWeek(DateTime.Now, new CultureInfo("fr-FR"), out begining, out end); tee.NextRunDate = end.AddDays(1); } else if (tee.AutoReportTimeID == 3) //month { DateTime Temp2 = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, 01, 00, 00, 01); tee.NextRunDate = Temp2; } else if (tee.AutoReportTimeID == 4) //year { DateTime Temp2 = new DateTime(DateTime.Now.AddYears(1).Year, 01, 01, 00, 00, 01); tee.NextRunDate = Temp2; } var DupData = db.tbl_autoreportsetting.Where(m => m.AutoReportID != tee.AutoReportID && m.ReportID == tee.ReportID && m.BasedOn == tee.BasedOn && m.AutoReportTimeID == tee.AutoReportTimeID && m.PlantID == tee.PlantID && m.ShopID == tee.ShopID && m.CellID == tee.CellID && m.MachineID == tee.MachineID).FirstOrDefault(); if (DupData != null) { ValidEscalation += " Duplicate Entry "; } if (ValidEscalation == null) { tee.ModifiedBy = UserID; tee.ModifiedOn = DateTime.Now; tee.IsDeleted = 0; db.Entry(tee).State = EntityState.Modified; db.SaveChanges(); } else { Session["Error"] = ValidEscalation; ViewBag.RL1 = new SelectList(db.tbl_reportmaster.Where(m => m.IsDeleted == 0), "ReportID", "ReportDispName", tee.ReportID); ViewBag.RL2 = new SelectList(db.tbl_autoreportbasedon.Where(m => m.IsDeleted == 0), "BasedOnID", "BasedOn", tee.BasedOn); ViewBag.RL3 = new SelectList(db.tbl_autoreporttime.Where(m => m.IsDeleted == 0), "AutoReportTimeID", "AutoReportTime", tee.AutoReportTimeID); ViewBag.Plant = new SelectList(db.tblplants.Where(m => m.IsDeleted == 0), "PlantID", "PlantName", tee.PlantID); ViewBag.Shop = new SelectList(db.tblshops.Where(m => m.IsDeleted == 0 && m.PlantID == tee.PlantID), "ShopID", "ShopName", tee.ShopID); ViewBag.Cell = new SelectList(db.tblcells.Where(m => m.IsDeleted == 0 && m.PlantID == tee.ShopID), "CellID", "CellName", tee.CellID); ViewBag.WorkCenter = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0 && m.IsNormalWC == 0 && m.PlantID == tee.PlantID && m.ShopID == tee.ShopID && m.CellID == tee.CellID), "MachineID", "MachineInvNo", tee.MachineID); return(View(tee)); } return(RedirectToAction("Index")); }
public ActionResult Edit(tblmailid tmi) { 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(); int UserID = Convert.ToInt32(Session["UserID"]); //MailID details validation string name = tmi.Name.ToString(); string emailid = tmi.EmailID.ToString(); string contactNo = tmi.ContactNo.ToString(); int MailIDDetailsID = tmi.MailIDsID; var doesTheseExists = db.tblmailids.Where(m => m.IsDeleted == 0 && (m.Name == name || m.EmailID == emailid || m.ContactNo == contactNo) && m.MailIDsID != MailIDDetailsID).ToList(); if (doesTheseExists.Count == 0) { #region Active Log Code //tblmachinecategory OldData = db.tblmachinecategories.Find(tblmc.ID); //IEnumerable<string> FullData = ActiveLog.EnumeratePropertyDifferences<tblmachinecategory>(OldData, tblmc); //ICollection<tblmachinecategory> c = FullData as ICollection<tblmachinecategory>; //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 tmi.ModifiedBy = UserID; tmi.ModifiedOn = DateTime.Now; db.Entry(tmi).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { Session["Error"] = null; var doesNameExists = db.tblmailids.Where(m => m.IsDeleted == 0 && m.Name == name && m.MailIDsID != MailIDDetailsID).ToList(); if (doesNameExists.Count > 0) { Session["Error"] += "Duplicate Name. "; } var doesMailIdExists = db.tblmailids.Where(m => m.EmailID == emailid && m.MailIDsID != MailIDDetailsID).ToList(); if (doesMailIdExists.Count > 0) { Session["Error"] += " Duplicate Email ID. "; } var doesCnoExists = db.tblmailids.Where(m => m.IsDeleted == 0 && m.ContactNo == contactNo && m.MailIDsID != MailIDDetailsID).ToList(); if (doesCnoExists.Count > 0) { Session["Error"] += " Duplicate Contact Number. "; } return(View(tmi)); } }
public ActionResult Index(IList <UnIdentifiedLossCorrection> UnIdentifiedL) { if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } string MacIDs = null; int i = 0; string CorrectedDate = null; if (UnIdentifiedL != null) { foreach (var row in UnIdentifiedL) { int LossCodeID = 0, LossID = 0; if (row.Level3 != 0) { LossCodeID = Convert.ToInt32(row.Level3); LossID = Convert.ToInt32(row.LossID); } else if (row.Level2 != 0) { LossCodeID = Convert.ToInt32(row.Level2); LossID = Convert.ToInt32(row.LossID); } else if (row.Level1 != 0 && row.Level1 != 999) { LossCodeID = Convert.ToInt32(row.Level1); LossID = Convert.ToInt32(row.LossID); } var LossData = db.tbllossofentries.Find(LossID); if (LossData != null) { //Get MacNumber if it doesn't exist in String(MacIDs) string MacID = Convert.ToString(LossData.MachineID); if (MacIDs == null) { MacIDs += MacID; } else { MacIDs += "," + MacID; } if (i == 0) { CorrectedDate = LossData.CorrectedDate; i++; } LossData.MessageCodeID = LossCodeID; string LossName = Convert.ToString(db.tbllossescodes.Where(m => m.LossCodeID == LossCodeID).Select(m => m.LossCode).FirstOrDefault()); LossData.MessageCode = LossName; LossData.MessageDesc = LossName; db.Entry(LossData).State = EntityState.Modified; db.SaveChanges(); } } } //Delete Data from tblworeport table and tbloeedashboardvariables string StartDate = Convert.ToString(CorrectedDate); MsqlConnection mcDeleteRows = new MsqlConnection(); try { try { DataTable LossCodesData = new DataTable(); string query = @"SELECT Distinct(HMIID) FROM i_facility_taml.dbo.tblworeport WHERE MachineID IN ( " + MacIDs + ") and CorrectedDate = '" + CorrectedDate + "';"; using (MsqlConnection mcLossCodes = new MsqlConnection()) { mcLossCodes.open(); SqlDataAdapter daLossCodesData = new SqlDataAdapter(query, mcLossCodes.msqlConnection); daLossCodesData.Fill(LossCodesData); mcLossCodes.close(); } mcDeleteRows.open(); SqlCommand cmdDeleteWOData = new SqlCommand("DELETE FROM i_facility_taml.dbo.tblworeport WHERE MachineID IN ( " + MacIDs + ") and CorrectedDate = '" + CorrectedDate + "';", mcDeleteRows.msqlConnection); cmdDeleteWOData.ExecuteNonQuery(); for (int l = 0; l < LossCodesData.Rows.Count; l++) { SqlCommand cmdDeleteWOLosses = new SqlCommand("DELETE FROM i_facility_taml.dbo.tblwolossess WHERE HMIID = '" + LossCodesData.Rows[l][0] + "' ", mcDeleteRows.msqlConnection); cmdDeleteWOLosses.ExecuteNonQuery(); } } catch (Exception e) { } try { SqlCommand cmdDeleteOEEData = new SqlCommand("DELETE FROM i_facility_taml.dbo.tbloeedashboardvariables WHERE WCID IN ( " + MacIDs + ") and StartDate = '" + StartDate + "';", mcDeleteRows.msqlConnection); cmdDeleteOEEData.ExecuteNonQuery(); } catch (Exception e) { } } catch (Exception e) { } finally { mcDeleteRows.close(); } //Insert New Data try { CalOEE_WODetails cwod = new CalOEE_WODetails(); cwod.CalculateOEEForYesterday(Convert.ToDateTime(CorrectedDate), Convert.ToDateTime(CorrectedDate)); cwod.CalWODataForYesterday(Convert.ToDateTime(CorrectedDate), Convert.ToDateTime(CorrectedDate)); } catch (Exception e) { } return(RedirectToAction("Index")); }
public ActionResult Edit(tblshiftmethod tblmc) { 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(); int UserID = Convert.ToInt32(Session["UserID"]); string shiftmethodname = tblmc.ShiftMethodName; int shiftmethodId = tblmc.ShiftMethodID; var doesthisExist = db.tblshiftmethods.Where(m => m.IsDeleted == 0 && m.ShiftMethodName == shiftmethodname && m.ShiftMethodID != shiftmethodId).ToList(); if (doesthisExist.Count == 0) { #region Active Log Code //tblmachinecategory OldData = db.tblmachinecategories.Find(tblmc.ID); //IEnumerable<string> FullData = ActiveLog.EnumeratePropertyDifferences<tblmachinecategory>(OldData, tblmc); //ICollection<tblmachinecategory> c = FullData as ICollection<tblmachinecategory>; //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 //check if shift method is in use or was used and now its being modified. ShiftDetails sd = new ShiftDetails(); int shiftmethodid = Convert.ToInt32(tblmc.ShiftMethodID); bool tick = sd.IsThisShiftMethodIsInActionOrEnded(shiftmethodid); if (tick) { tblshiftmethod tsm = new tblshiftmethod(); tsm.CreatedBy = UserID; tsm.CreatedOn = DateTime.Now; tsm.IsDeleted = 0; tsm.NoOfShifts = tblmc.NoOfShifts; tsm.ShiftMethodDesc = tblmc.ShiftMethodDesc; tsm.ShiftMethodName = tblmc.ShiftMethodName; db.tblshiftmethods.Add(tsm); db.SaveChanges(); tblmc.ModifiedBy = UserID; tblmc.ModifiedOn = DateTime.Now; db.Entry(tblmc).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { tblmc.ModifiedBy = UserID; tblmc.ModifiedOn = DateTime.Now; db.Entry(tblmc).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } else { TempData["Error"] = "Shift Method Exists."; return(View(tblmc)); } }
public ActionResult Edit(IEnumerable <tblshiftdetail> tblp, int ShiftMethod = 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(); int UserID = Convert.ToInt32(Session["UserID"]); var shiftmethodiddata = db.tblshiftmethods.Where(m => m.IsDeleted == 0 && m.ShiftMethodID == ShiftMethod).SingleOrDefault(); int noofshifts = shiftmethodiddata.NoOfShifts; int rowscount = 0; //insert isedited and other details into old rows and insert the new rows. var shiftDetailsData = db.tblshiftdetails.Where(m => m.IsDeleted == 0 && m.ShiftMethodID == ShiftMethod).ToList(); //check if shift method is in use or was used and now its being modified. ShiftDetails sd = new ShiftDetails(); int shiftmethodid = Convert.ToInt32(ShiftMethod); bool tick = sd.IsThisShiftMethodIsInActionOrEnded(shiftmethodid); try { foreach (var shift in tblp) { if (rowscount < noofshifts) { using (i_facility_tamlEntities db3 = new i_facility_tamlEntities()) { // calculate duration int duration = 0; string starttimestring = "2016-06-02" + " " + shift.ShiftStartTime; DateTime starttimedatetime = Convert.ToDateTime(starttimestring); string endtimestring = null; TimeSpan tsStart = (System.TimeSpan)shift.ShiftStartTime; TimeSpan tsEnd = (System.TimeSpan)shift.ShiftEndTime; int result = TimeSpan.Compare(tsStart, tsEnd); if (result < 0) { endtimestring = "2016-06-02" + " " + shift.ShiftEndTime; } else if (result > 0) { endtimestring = "2016-06-03" + " " + shift.ShiftEndTime; shift.NextDay = 1; } DateTime endtimedatetime = Convert.ToDateTime(endtimestring); TimeSpan ts = endtimedatetime.Subtract(starttimedatetime); duration = Convert.ToInt32(ts.TotalMinutes); if (tick) { //create new object/row int shiftid = shift.ShiftDetailsID; int oldcreatedby = 0; DateTime oldcreatedon = DateTime.Now; using (i_facility_tamlEntities db1 = new i_facility_tamlEntities()) { var getShiftId = db1.tblshiftdetails.Where(m => m.IsDeleted == 0 && m.ShiftDetailsID == shiftid).SingleOrDefault(); getShiftId.IsShiftDetailsEdited = 1; getShiftId.IsDeleted = 1; getShiftId.ShiftMethodID = ShiftMethod; getShiftId.ShiftDetailsEditedDate = DateTime.Now; oldcreatedon = Convert.ToDateTime(getShiftId.CreatedOn); oldcreatedby = Convert.ToInt32(getShiftId.CreatedBy); ViewBag.ShiftMethod = new SelectList(db.tblshiftmethods.Where(m => m.IsDeleted == 0), "ShiftMethodID", "ShiftMethodName", shift.ShiftMethodID); db1.Entry(getShiftId).State = EntityState.Modified; db1.SaveChanges(); } tblshiftdetail tsd = new tblshiftdetail(); tsd.Duration = duration; tsd.IsDeleted = 0; tsd.CreatedBy = oldcreatedby; tsd.CreatedOn = oldcreatedon; tsd.ModifiedBy = UserID; tsd.ModifiedOn = DateTime.Now; tsd.IsDeleted = 0; tsd.NextDay = shift.NextDay; tsd.ShiftMethodID = ShiftMethod; tsd.ShiftDetailsDesc = shift.ShiftDetailsName; tsd.ShiftDetailsName = shift.ShiftDetailsDesc; tsd.ShiftEndTime = shift.ShiftEndTime; tsd.ShiftStartTime = shift.ShiftStartTime; db.tblshiftdetails.Add(tsd); db.SaveChanges(); } else { //create new object/row shift.ModifiedBy = UserID; shift.ModifiedOn = DateTime.Now; shift.Duration = duration; shift.IsDeleted = 0; shift.ShiftMethodID = ShiftMethod; db3.Entry(shift).State = EntityState.Modified; db3.SaveChanges(); } } } rowscount++; } } catch (Exception e) { ViewBag.ShiftMethod = new SelectList(db.tblshiftmethods.Where(m => m.IsDeleted == 0), "ShiftMethodID", "ShiftMethodName", ShiftMethod); return(View(tblp)); } return(RedirectToAction("Index")); }