public ActionResult SaveEmployee(EmployeeObject employeeObj) { if (employeeObj.EmpID == 0) // if ID == 0, its a new entry { EMPLOYEE _e = new EMPLOYEE(); _e.EMP_NAME = employeeObj.EmpName; _e.EMP_EMAIL = employeeObj.EmpEmail; _e.EMP_PHONE = employeeObj.EmpPhone; _e.EMP_SALARY = employeeObj.EmpSalary; _e.EMP_HIRE_DATE = DateTime.Today; _e.EMP_GENDER = employeeObj.EmpGender; _e.EMP_PHOTO = null; _e.EMP_IS_ACTIVE = true; _repository.AddNewEmployee(_e); } else if (employeeObj.EmpID > 0) //if ID field is not 0, it is an update!!! { EMPLOYEE _e = new EMPLOYEE(); _e.EMP_ID = employeeObj.EmpID; _e.EMP_NAME = employeeObj.EmpName; _e.EMP_EMAIL = employeeObj.EmpEmail; _e.EMP_PHONE = employeeObj.EmpPhone; _e.EMP_SALARY = employeeObj.EmpSalary; _e.EMP_HIRE_DATE = Convert.ToDateTime(employeeObj.EmpHireDate); _e.EMP_GENDER = employeeObj.EmpGender; _e.EMP_PHOTO = null; _e.EMP_IS_ACTIVE = employeeObj.EmpIsActive ; _repository.UpdateEmployee(_e); } var _employees = _repository.GetAllEmployeeDataNoPhoto().OrderByDescending(x => x.EmpID).AsQueryable(); return CreateFlexiJson(_employees.ToList(), 1, _employees.Count()); }
public bool AddNewEmployee(EMPLOYEE newEmpModel) { bool _retVal = false; _context.EMPLOYEEs.Add(newEmpModel); _context.SaveChanges(); _retVal = true; return _retVal; }
public ActionResult Create(EmployeeObject newEmployeeModel) { if (ModelState.IsValid) { if (newEmployeeModel.File != null) { int maxFileSize = 1024 * 1024 * 2; //2MB string[] AllowedFileExtensions = new string[] { ".jpg" }; var attachedFile = newEmployeeModel.File; var fileSize = attachedFile.ContentLength; if (fileSize > maxFileSize) { ModelState.AddModelError("File", "File is greater than 2MB. Choose a smaller file and try again."); } else { if (!AllowedFileExtensions.Contains(newEmployeeModel.File.FileName.Substring(newEmployeeModel.File.FileName.LastIndexOf('.')))) { ModelState.AddModelError("File", "Allowed file types are: " + string.Join(", ", AllowedFileExtensions)); } else { EMPLOYEE _newEmployee = new EMPLOYEE(); _newEmployee.EMP_NAME = newEmployeeModel.EmpName; _newEmployee.EMP_EMAIL = newEmployeeModel.EmpEmail; _newEmployee.EMP_PHONE = newEmployeeModel.EmpPhone; _newEmployee.EMP_IS_ACTIVE = true; _newEmployee.EMP_HIRE_DATE = DateTime.Today.Date; _newEmployee.EMP_GENDER = newEmployeeModel.EmpGender; _newEmployee.EMP_SALARY = newEmployeeModel.EmpSalary; _newEmployee.EMP_PHOTO = new byte[fileSize]; newEmployeeModel.File.InputStream.Read(_newEmployee.EMP_PHOTO, 0, fileSize); if (_repository.AddNewEmployee(_newEmployee)) { Success(string.Format("<b>{0}</b> New Employee Added successfully!.", "SUCCESS"), true); return RedirectToAction("Index"); } } } } else { ModelState.AddModelError("File", "Employee photo is required!"); return View(newEmployeeModel); } } return View(newEmployeeModel); }
public ActionResult Create(EmployeeObject newEmployeeModel) { if (ModelState.IsValid) { if (newEmployeeModel.EmpPhone.Length > 0) { string _phoneNumberPattern = @"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$"; if (!Regex.IsMatch(newEmployeeModel.EmpPhone, _phoneNumberPattern)) { ModelState.AddModelError("", "Invalid Phone number entered!"); } else { EMPLOYEE _model = new EMPLOYEE(); _model.EMP_NAME = newEmployeeModel.EmpName; _model.EMP_EMAIL = newEmployeeModel.EmpEmail; _model.EMP_PHONE = newEmployeeModel.EmpPhone; _model.EMP_SALARY = newEmployeeModel.EmpSalary; _model.EMP_IS_ACTIVE = true; _model.EMP_HIRE_DATE = DateTime.Now; _model.EMP_GENDER = newEmployeeModel.EmpGender; _repository.AddNewEmployee(_model); Success(string.Format("<b>{0}</b> New Employee Added succcessfully!.", "SUCCESS"), true); return RedirectToAction("Index"); } } else { ModelState.AddModelError("", "Invalid Phone number entered!"); } } return View(newEmployeeModel); }
public ActionResult Edit(EmployeeObject updatedEmployeeModel) { ViewBag.EmployeeStatus = GetActiveStatusList(updatedEmployeeModel.EmpStatus); if (ModelState.IsValid) { if (updatedEmployeeModel.EmpPhone.Length > 0) { string _phoneNumberPattern = @"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$"; if (!Regex.IsMatch(updatedEmployeeModel.EmpPhone, _phoneNumberPattern)) { ModelState.AddModelError("", "Invalid Phone number entered!"); } else { EMPLOYEE _model = new EMPLOYEE(); _model.EMP_ID = updatedEmployeeModel.EmpID; _model.EMP_NAME = updatedEmployeeModel.EmpName; _model.EMP_EMAIL = updatedEmployeeModel.EmpEmail; _model.EMP_PHONE = updatedEmployeeModel.EmpPhone; _model.EMP_SALARY = updatedEmployeeModel.EmpSalary; _model.EMP_GENDER = updatedEmployeeModel.EmpGender; if (updatedEmployeeModel.EmpStatus == "No") { _model.EMP_IS_ACTIVE = false; } else if (updatedEmployeeModel.EmpStatus == "Yes") { _model.EMP_IS_ACTIVE = true; } _model.EMP_HIRE_DATE = Convert.ToDateTime(updatedEmployeeModel.EmpHireDate); _repository.UpdateEmployee(_model); Success(string.Format("<b>{0}</b> Employee Edited succcessfully!.", "SUCCESS"), true); return RedirectToAction("Index"); } } else { ModelState.AddModelError("", "Invalid Phone number entered!"); } } return View(updatedEmployeeModel); }
public bool UpdateEmployee(EMPLOYEE updatedEmpModel) { bool _retVal = false; var _empToUpdate = _context.EMPLOYEEs.Find(updatedEmpModel.EMP_ID); if (_empToUpdate != null) { _context.Entry(_empToUpdate).CurrentValues.SetValues(updatedEmpModel); _context.SaveChanges(); _retVal = true; } return _retVal; }