Esempio n. 1
0
        /// <summary>
        /// Giao diện thông tin người dùng
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            WebUserData userData = User.GetUserData();
            Employee    model    = HumanResourceBLL.Employee_Get(Convert.ToInt32(userData.UserID));

            return(View(model));
        }
        public ActionResult UpdateProfile(Account model, HttpPostedFileBase uploadPhoto)
        {
            try
            {
                if (uploadPhoto != null)
                {
                    string filePath = Path.Combine(Server.MapPath("~/Images"), uploadPhoto.FileName);
                    model.PhotoPath = uploadPhoto.FileName;
                    uploadPhoto.SaveAs(filePath);

                    bool updateResult = AccountBLL.UpdateProfile(model);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    Employee employee = HumanResourceBLL.Employee_Get(model.EmployeeID);
                    model.PhotoPath = employee.PhotoPath;
                    bool updateResult = AccountBLL.UpdateProfile(model);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message + ":" + ex.StackTrace);
                return(View(model));
            }
        }
Esempio n. 3
0
 /// <summary>
 /// add or edit
 /// </summary>
 /// <param name=""></param>
 /// <param name=""></param>
 /// <returns></returns>
 public ActionResult Input(string id = "")
 {
     if (string.IsNullOrEmpty(id))
     {
         ViewBag.Title = "Add new Employee";
         Employee newEmployss = new Employee();
         newEmployss.EmployeeID = 0;
         return(View(newEmployss));
     }
     else
     {
         ViewBag.Type  = "Edit";
         ViewBag.Title = "Edit Employee";
         Employee editEmployee = HumanResourceBLL.Employee_Get(Convert.ToInt32(id));
         return(View(editEmployee));
     }
 }
        public ActionResult Input(string id = "")
        {
            if (string.IsNullOrEmpty(id))
            {
                ViewBag.Title         = "Add New Employee";
                ViewBag.ConfirmButton = "Add";
                ViewBag.Method        = "add";

                Employee newEmployee = new Employee();
                newEmployee.EmployeeID = 0;
                return(View(newEmployee));
            }
            else
            {
                WebUserData userData = User.GetUserData();
                string      idCookie = userData.UserID;

                if (id.Equals(idCookie))
                {
                    return(Redirect("~/Account"));
                }
                else
                {
                    ViewBag.Title         = "Edit Employee";
                    ViewBag.ConfirmButton = "Save";
                    ViewBag.Method        = "update";
                    try
                    {
                        Employee editEmployee = HumanResourceBLL.Employee_Get(Convert.ToInt32(id));
                        if (editEmployee == null)
                        {
                            return(RedirectToAction("Index"));
                        }
                        return(View(editEmployee));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        return(RedirectToAction("Index"));
                    }
                }
            }
        }
 public ActionResult Input(string id = "")
 {
     if (String.IsNullOrEmpty(id))
     {
         ViewBag.Title = "Add Employee";
         Employee newEmployee = new Employee();
         newEmployee.EmployeeID = 0;
         return(View(newEmployee));
     }
     else
     {
         ViewBag.Title = "Edit Employee";
         Employee editEmployee = HumanResourceBLL.Employee_Get(Convert.ToInt32(id));
         if (editEmployee == null)
         {
             return(RedirectToAction("Index"));
         }
         return(View(editEmployee));
     }
 }
Esempio n. 6
0
        public ActionResult EditAccount(Employee model, HttpPostedFileBase fileImage = null)
        {
            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);
                model.PhotoPath = fileName;
                fileImage.SaveAs(path);
            }
            if (fileImage == null)
            {
                var getEmployee = HumanResourceBLL.Employee_Get(model.EmployeeID);
                model.PhotoPath = getEmployee.PhotoPath;
            }

            bool updateResult = UserAccountBLL.UpdateProfile(model);

            return(RedirectToAction("Index"));
        }
        public ActionResult Input(Employee model, HttpPostedFileBase file = null, string oldEmail = "")
        {
            //try
            //{
            //    //Kiểm tra tính hợp lệ
            if (model.Notes == null)
            {
                model.Notes = "";
            }
            if (String.IsNullOrEmpty(model.Country))
            {
                ModelState.AddModelError("errorAddr", "Vui lòng chọn quốc gia");
            }
            if (String.IsNullOrEmpty(model.GroupName))
            {
                ModelState.AddModelError("errorRole", "Vui lòng chọn quyền");
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var    listRoles = model.GroupName.Split(',');
            string groupName = "";

            foreach (var item in SelectListHelper.listRoles(false))
            {
                foreach (var role in listRoles)
                {
                    if (item.Value == role)
                    {
                        groupName += role + ",";
                    }
                }
            }
            model.GroupName = groupName.Remove(groupName.LastIndexOf(','));
            if (file != null)
            {
                string get           = DateTime.Now.ToString("ddMMyyyhhmmss");
                string fileExtension = Path.GetExtension(file.FileName);
                string fileName      = get + fileExtension;
                string path          = Path.Combine(Server.MapPath("~/Images"), fileName);
                model.PhotoPath = fileName;
                file.SaveAs(path);
            }
            if (!EncodeMD5.IsMD5(model.Password))
            {
                model.Password = EncodeMD5.GetMD5(model.Password);
            }
            if (model.EmployeeID == 0)
            {
                if (file == null)
                {
                    TempData["emptyFile"] = "Vui lòng chọn file";
                    return(View(model));
                }
                else if (HumanResourceBLL.Check_Email(model.Email))
                {
                    TempData["emptyEmail"] = "Email đã tồn tại";
                    return(View(model));
                }
                else
                {
                    int employeeID = HumanResourceBLL.Employee_Add(model);
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                if (HumanResourceBLL.Check_Email(model.Email) && (oldEmail != model.Email))
                {
                    TempData["emptyEmail"] = "Email đã tồn tại";
                    ViewBag.oldEmail       = oldEmail;
                    return(View(model));
                }
                var getEmployee = HumanResourceBLL.Employee_Get(model.EmployeeID);
                if (file == null)
                {
                    model.PhotoPath = getEmployee.PhotoPath;
                }

                bool updateResult = HumanResourceBLL.Employee_Update(model);
                return(RedirectToAction("Index"));
            }

            //}
            //catch (Exception e)
            //{
            //    ModelState.AddModelError("", e.Message + ":" + e.StackTrace);
            //    return View(model);
            //}
        }
        public ActionResult Input(Employee model, HttpPostedFileBase uploadPhoto)
        {
            try
            {
                //kiem tra tinh hop le
                if (string.IsNullOrEmpty(model.FirstName))
                {
                    ModelState.AddModelError("FirstName", "First Name is required");
                }
                if (string.IsNullOrEmpty(model.LastName))
                {
                    ModelState.AddModelError("LastName", "Last Name is required");
                }
                if (string.IsNullOrEmpty(model.Password))
                {
                    ModelState.AddModelError("Password", "Password is required");
                }
                if (string.IsNullOrEmpty(model.City))
                {
                    ModelState.AddModelError("City", "City is required");
                }
                if (string.IsNullOrEmpty(model.Country))
                {
                    ModelState.AddModelError("Country", "Country is required");
                }
                if (string.IsNullOrEmpty(model.Email))
                {
                    ModelState.AddModelError("Email", "Email is required");
                }
                if (string.IsNullOrEmpty(model.Address))
                {
                    model.Address = "";
                }
                if (string.IsNullOrEmpty(model.HomePhone))
                {
                    model.HomePhone = "";
                }
                if (string.IsNullOrEmpty(model.Title))
                {
                    model.Title = "";
                }
                if (string.IsNullOrEmpty(model.Notes))
                {
                    model.Notes = "";
                }
                if (string.IsNullOrEmpty(model.PhotoPath))
                {
                    model.PhotoPath = "";
                }

                if (!ConvertMD5.IsMD5(model.Password))
                {
                    model.Password = ConvertMD5.GetMD5(model.Password);
                }
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                if (model.EmployeeID == 0)
                {
                    if (uploadPhoto != null)
                    {
                        string filePath = Path.Combine(Server.MapPath("~/Images"), uploadPhoto.FileName);
                        model.PhotoPath = uploadPhoto.FileName;
                        uploadPhoto.SaveAs(filePath);
                        int employeeID = HumanResourceBLL.Employee_Add(model);
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        model.PhotoPath = "";
                        int employeeID = HumanResourceBLL.Employee_Add(model);
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    if (uploadPhoto != null)
                    {
                        string filePath = Path.Combine(Server.MapPath("~/Images"), uploadPhoto.FileName);
                        model.PhotoPath = uploadPhoto.FileName;
                        uploadPhoto.SaveAs(filePath);
                        bool rs = HumanResourceBLL.Employee_Update(model);
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        Employee employee = HumanResourceBLL.Employee_Get(model.EmployeeID);
                        model.PhotoPath = employee.PhotoPath;
                        bool rs = HumanResourceBLL.Employee_Update(model);
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message + ":" + ex.StackTrace);
                return(View(model));
            }
        }