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 Save() { var Code = Request.Form["Code"].ToUpper(); var Description = Request.Form["Description"].ToUpper(); var Point = Convert.ToInt32(Request.Form["Point"]); var Type = Request.Form["Type"]; using (lear_DailiesCertificationRequirementEntities ldcr = new lear_DailiesCertificationRequirementEntities()) { var exist = ldcr.Certifications.Where(cert => cert.Code == Code).FirstOrDefault(); if (exist == null) { Certification certification = new Certification { Code = Code, Description = Description, Points = Point, Type = Type }; ldcr.Certifications.Add(certification); ldcr.SaveChanges(); } } return(RedirectToAction("Certificates", "Certificate")); }
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 PostCertified() { // [ GET Data from submitted form -- var DateP = Request.Form["DateCertified"]; var Who = Request.Form["Employee"]; var Code = Request.Form["Code"]; var RedirectURL = Request.Form["URLBACK"]; var TrainingDate = Request.Form["TrainingDate"]; // ---------------------- var message = ""; // initialize variable for message List <String> error = new List <string>(); // initialize variable for error CertificationTracker certificationTracker = new CertificationTracker(); // Validate Data submitted if (DateP != null && Who != null && Code != null && Code != "X" && !String.IsNullOrEmpty(DateP) && TrainingDate != null && !String.IsNullOrEmpty(TrainingDate)) { // 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.DateCertified = DateTime.ParseExact(DateP, "MM/dd/yyyy", CultureInfo.InvariantCulture); } else { error.Add("Date Certified is not Valid!"); } if (Validator.isValidDate(TrainingDate)) { certificationTracker.TrainingDate = DateTime.ParseExact(TrainingDate, "MM/dd/yyyy", CultureInfo.InvariantCulture); } else { error.Add("TrainingDate is not Valid!"); } if (error.Count > 0) { foreach (var da in error) { System.Diagnostics.Debug.WriteLine(da); } } else { var TempCertificationTracker = ldcr.CertificationTrackers.Where(ct => ct.EmpBadgeNo == certificationTracker.EmpBadgeNo && ct.CertificationCode == certificationTracker.CertificationCode).FirstOrDefault(); if (TempCertificationTracker == null) { // Add the new Tracker ldcr.CertificationTrackers.Add(certificationTracker); ldcr.SaveChanges(); message = emp.Last_Name + " , " + emp.First_Name + " is successfully certified in " + certificationTracker.CertificationCode; return(RedirectToAction("ModalSuccess", "IT", new { message = message, id = Who, urlBack = "Details", redirectUrl = RedirectURL })); } } return(RedirectToAction("ModalFailed", "IT", new { message = message, id = Who, urlBack = "Certified", redirectUrl = RedirectURL })); } else { if (DateP == null || String.IsNullOrEmpty(DateP)) { ModelState.AddModelError("", "Please provide date certified."); message += "Please provide date certified."; } if (TrainingDate == null || String.IsNullOrEmpty(TrainingDate)) { ModelState.AddModelError("", "Please provide Training Date."); message += "Please provide Training Date."; } if (Code == "X") { ModelState.AddModelError("", "Please choose certification code"); message = "Please choose certification code"; } return(RedirectToAction("ModalFailed", "IT", new { message = message, id = Who, urlBack = "Certified", redirectUrl = RedirectURL })); } }
public async Task <ActionResult> Register(Account model) { _EmployeesManager = new commonEmployeesEntities(); _AccountManager = new lear_DailiesCertificationRequirementEntities(); // Check if model is Valid if (ModelState.IsValid) { // Check if password is Match System.Diagnostics.Debug.WriteLine(Request["Confirm"].ToString() + "___" + model.Password); if (model.Password == Request["Confirm"].ToString()) { // Check if BadgeNo is exist!; var user = _EmployeesManager.Employees_Details.Where(u => u.Employee_ID == model.BagdeNo).SingleOrDefault(); if (user != null) { // Check if account is already exist var account = _AccountManager.Users.Where(a => a.BadgeNo == model.BagdeNo).SingleOrDefault(); if (account != null) { ModelState.AddModelError("", "Account already exist"); } else //if not save to User table { var users = _EmployeesManager.Database.SqlQuery <Approver>("Select * from approvers").ToList <Approver>(); model.Roles = "Default"; foreach (Approver app in users) { System.Diagnostics.Debug.WriteLine(app.approver); if (model.BagdeNo.Equals(app.approver.ToString())) { model.Roles = "Approver"; break; } } // Implement here Password:Encryption PasswordSecurity ps = new PasswordSecurity(); var pass = ps.Encryptdata(model.Password); //System.Diagnostics.Debug.WriteLine(pass); //System.Diagnostics.Debug.WriteLine(ps.Decryptdata(pass)+"DECRYPTED"); User useraccount = new User() { BadgeNo = model.BagdeNo, Roles = model.Roles, Password = pass }; _AccountManager.Users.Add(useraccount); _AccountManager.SaveChanges(); return(RedirectToAction("Home", "Home")); } } else { ModelState.AddModelError("", "BadgeNo is not exist"); } } else { ModelState.AddModelError("", "Password is not Match!"); } //return RedirectToAction("Index", "Home"); } return(View(model)); }