예제 #1
0
 public ActionResult Input(string id = "")
 {
     if (string.IsNullOrEmpty(id))
     {
         ViewBag.Title = "Add Employee";
         Employee newEmployee = new Employee();
         newEmployee.EmployeeID = 0;
         return(View(newEmployee));
     }
     else
     {
         Employee editEmployee = HumanResourceBLL.GetEmployee(Convert.ToInt32(id));
         if (editEmployee == null)
         {
             return(RedirectToAction("Index"));
         }
         ViewBag.Title = "Edit Employee";
         return(View(editEmployee));
     }
 }
예제 #2
0
        public ActionResult ChangeInfo(Employee data, HttpPostedFileBase fileImage = null)
        {
            if (data != null)
            {
                Employee getEmployee = HumanResourceBLL.GetEmployee(data.EmployeeID);
                data.PhotoPath = getEmployee.PhotoPath;
                data.Password  = getEmployee.Password;
                data.Notes     = getEmployee.Notes;

                if (fileImage != null)
                {
                    string get           = DateTime.Now.ToString("ddMMyyyhhmmss");
                    string fileExtension = Path.GetExtension(fileImage.FileName);
                    string fileName      = get + fileExtension;
                    string path          = Path.Combine(Server.MapPath("~/Images"), fileName);
                    data.PhotoPath = fileName;
                    fileImage.SaveAs(path);
                }
                if (fileImage == null)
                {
                    data.PhotoPath = getEmployee.PhotoPath;
                }

                bool IsEmailExist = AccountBLL.IsEmailExist(getEmployee.Email, getEmployee.EmployeeID);
                if (IsEmailExist)
                {
                    ModelState.AddModelError("errorEmailDuplicate1", "Email đã tồn tại. Vui lòng nhập email khác!");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    bool editUser = HumanResourceBLL.Employee_Update(data);
                }
            }
            return(RedirectToAction("Index"));
        }