public ActionResult AssignNewCell() { var EmpID = Request.Form["EmployeeID"]; var Hrccell = Request.Form["HrcCell"]; var Cell = Request.Form["Cell"]; var PageNum = Request.Form["PageNum"]; var Urlback = Request.Form["UrlBack"]; if (Cell == "X") { Cell = ""; } var EmpDcr = ldcr.EmployeeDCRs.Where(emp => emp.BadgeNo == EmpID).FirstOrDefault(); if (EmpDcr == null) { EmployeeDCR dcr = new EmployeeDCR { BadgeNo = EmpID, HRCCell = Hrccell, CurrentCell = Cell }; ldcr.EmployeeDCRs.Add(dcr); ldcr.SaveChanges(); } else { EmpDcr.CurrentCell = Cell; ldcr.Entry(EmpDcr).State = EntityState.Modified; ldcr.SaveChanges(); } return(RedirectToAction(Urlback, "Search", new { page = PageNum })); }
public ActionResult PostEdit([Bind(Include = "Id,Code,Description,Points")] Certification certification) { var oldCode = Request.Form["OldCode"].ToString(); var Type = Request.Form["Type"]; using (lear_DailiesCertificationRequirementEntities db = new lear_DailiesCertificationRequirementEntities()) { if (ModelState.IsValid) { if (oldCode.Equals(certification.Code.ToUpper())) { certification.Code = certification.Code.ToUpper(); certification.Description = certification.Description.ToUpper(); certification.Type = Type; db.Entry(certification).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Certificates")); } else { if (db.Certifications.Where(crt => crt.Code == certification.Code.ToUpper()).FirstOrDefault() == null) { certification.Code = certification.Code.ToUpper(); certification.Description = certification.Description.ToUpper(); certification.Type = Type; db.Entry(certification).State = EntityState.Modified; db.SaveChanges(); db.UpdateLDCRTablesWhenUpdateCertification(oldCode, certification.Code); return(RedirectToAction("Certificates")); } else { return(RedirectToAction("ModalFailed", new { id = certification.Id, errorMessage = "Code is already used! It must be unique. " })); } } } } return(RedirectToAction("Edit", new { id = certification.Id.ToString() })); }
public ActionResult PostReCertified() { var DateP = Request.Form["DateReCertified"]; var Who = Request.Form["Employee"]; var Code = Request.Form["Code"]; var RedirectURL = Request.Form["URLBACK"]; var message = ""; List <String> error = new List <string>(); CertificationTracker certificationTracker = new CertificationTracker(); if (DateP != null && Who != null && Code != null && Code != "X" && !String.IsNullOrEmpty(DateP)) { // Check if Employee is Exist var emp = cEE.Employees_Details.Where(u => u.Employee_ID.ToString().ToLower() == Who.ToString().ToLower()).FirstOrDefault(); if (emp != null) { certificationTracker.EmpBadgeNo = emp.Employee_ID; } else { error.Add("BadgeNo not exist"); } // Check if certification Code is Exist var code = ldcr.Certifications.Where(c => c.Code == Code).FirstOrDefault(); if (code != null) { certificationTracker.CertificationCode = code.Code; } else { error.Add("Certification Code not exist"); } if (Validator.isValidDate(DateP)) { // CertificationTracker ctr = new CertificationTracker(); var ctr = ldcr.CertificationTrackers.Where(cTr => cTr.EmpBadgeNo == Who && cTr.CertificationCode == Code).FirstOrDefault(); if (ctr != null) { DateTime dtValue = (DateTime)ctr.DateCertified; String Date = ""; if (dtValue.Month.ToString().Length > 1) { Date += dtValue.Month.ToString() + "/"; } else { Date += "0" + dtValue.Month.ToString() + "/"; } if (dtValue.Day.ToString().Length > 1) { Date += dtValue.Day.ToString() + "/"; } else { Date += "0" + dtValue.Day.ToString() + "/"; } Date += dtValue.Year.ToString(); if (Validator.compareTwoDate(DateP, Date)) { certificationTracker.DateCertified = DateTime.ParseExact(DateP, "MM/dd/yyyy", CultureInfo.InvariantCulture); } else { error.Add("Date is prior to Last Certified Date!"); message += "Date is prior to Last Certified Date!"; } } } else { error.Add("Date is not Valid!"); } if (error.Count > 0) { foreach (var da in error) { System.Diagnostics.Debug.WriteLine(da); } return(RedirectToAction("ModalFailed", "IT", new { message = message, id = Who, urlBack = "ReCertified", redirectUrl = RedirectURL })); } else { var TempCertificationTracker = ldcr.CertificationTrackers.Where(ct => ct.EmpBadgeNo == certificationTracker.EmpBadgeNo && ct.CertificationCode == certificationTracker.CertificationCode).FirstOrDefault(); if (TempCertificationTracker != null) { // Update that tracker System.Diagnostics.Debug.WriteLine(certificationTracker.CertificationCode + " --- " + certificationTracker.EmpBadgeNo + " -- " + certificationTracker.DateCertified); TempCertificationTracker.DateRecertified = certificationTracker.DateCertified; ldcr.Entry(TempCertificationTracker).State = EntityState.Modified; ldcr.SaveChanges(); //ldcr.CertificationTrackers.Find(TempCertificationTracker); // DELETE RECERTIFACTION PLan Of the Employee // ldcr.deleteLastPlan(TempCertificationTracker.EmpBadgeNo); Session["NumberOfRecertificationPlans"] = Convert.ToInt32(Session["NumberOfRecertificationPlans"]) - 1; message = emp.Last_Name + " , " + emp.First_Name + " is succesfully Re-Certified in " + TempCertificationTracker.CertificationCode; } return(RedirectToAction("ModalSuccess", "IT", new { message = message, id = Who, urlBack = "Details", redirectUrl = RedirectURL })); } } else { if (DateP == null || String.IsNullOrEmpty(DateP)) { ModelState.AddModelError("", "Please provide date certified."); message += "Please provide date Re-certified."; } if (Code == "X") { ModelState.AddModelError("", "Please choose certification code"); message = "Please choose certification code"; } return(RedirectToAction("ModalFailed", "IT", new { message = message, id = Who, urlBack = "ReCertified", redirectUrl = RedirectURL })); } }