/// <summary>
        /// trang chủ của nhân viên
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            WebUserData userData = User.GetUserData();
            Employee    employee = CataLogBLL.GetEmployee(Convert.ToInt32(userData.UserID));

            return(View(employee));
        }
Example #2
0
 public ActionResult Input(string id = "")
 {
     try
     {
         if (string.IsNullOrEmpty(id))
         {
             ViewBag.Title = " Create new Employee";
             Employee newEmployee = new Employee()
             {
                 EmployeeID = 0
             };
             return(View(newEmployee));
         }
         else
         {
             ViewBag.Title = "Edit a Employee";
             Employee editEmployee = CataLogBLL.GetEmployee(Convert.ToInt32(id));
             if (editEmployee == null)
             {
                 return(RedirectToAction("Index"));
             }
             return(View(editEmployee));
         }
         // return View();
     }catch (Exception ex)
     {
         return(Content(ex.Message + "" + ex.StackTrace));
     }
 }
        public ActionResult ChangePassword(string pw = "", string pwn = "", string confirmpw = "")
        {
            WebUserData userData = User.GetUserData();
            Employee    employee = CataLogBLL.GetEmployee(Convert.ToInt32(userData.UserID));

            if (employee.Password.Equals(MaHoaMD5Hepler.EncodeMD5(pw)))
            {
                if (pwn.Equals(confirmpw))
                {
                    UserAccountBLL.ChangePassword(MaHoaMD5Hepler.EncodeMD5(pwn), employee.Email);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("MatKhau", "Mật khẩu không khớp!");
                    return(View());
                }
            }
            else
            {
                ModelState.AddModelError("MatKhauMoi", "Mật Khẩu không đúng!");
                return(View());
            }
        }
Example #4
0
        public ActionResult Input(Employee model, HttpPostedFileBase uploadFile, string EmailNew)
        {
            // Up anh
            if (uploadFile != null)
            {
                string fileName = $"{DateTime.Now.Ticks}{Path.GetExtension(uploadFile.FileName)}";
                // string _fileName = string.Format{"{0}{1}"} $"{DateTime.Now.Ticks}{Path.GetExtension(uploadFile.FileName)}";
                // string _FileName = Path.GetFileName(uploadFile.FileName);
                string filePath = Path.Combine(Server.MapPath("~/Images"), fileName);
                uploadFile.SaveAs(filePath);
                model.PhotoPath = fileName;
            }
            try
            {
                if (string.IsNullOrEmpty(model.FirstName))
                {
                    ModelState.AddModelError("FirstName", "FirstName expected");
                }
                if (string.IsNullOrEmpty(model.LastName))
                {
                    ModelState.AddModelError("LastName", "LastName expected");
                }
                if (string.IsNullOrEmpty(model.Title))
                {
                    ModelState.AddModelError("Title", "Title expected");
                }
                if (string.IsNullOrEmpty(EmailNew))
                {
                    ModelState.AddModelError("Email", "Email expected!");
                }
                if (string.IsNullOrEmpty(model.Address))
                {
                    model.Address = "";
                }
                if (string.IsNullOrEmpty(model.City))
                {
                    model.City = "";
                }
                if (string.IsNullOrEmpty(model.Country))
                {
                    model.Country = "";
                }
                if (string.IsNullOrEmpty(model.HomePhone))
                {
                    model.HomePhone = "";
                }
                if (string.IsNullOrEmpty(model.Notes))
                {
                    model.Notes = "";
                }
                if (string.IsNullOrEmpty(model.PhotoPath))
                {
                    model.PhotoPath = "";
                }
                if (string.IsNullOrEmpty(model.Password))
                {
                    model.Password = "";
                }
                if (CataLogBLL.CheckEmail(EmailNew) != 0 && EmailNew.Equals(model.Email) == false)
                {
                    ModelState.AddModelError("Email", "Email đã có người dùng!");
                    ViewBag.Title = model.EmployeeID == 0 ? "Create new Employee" : "Edit a Employee";
                    Employee editEmployee = CataLogBLL.GetEmployee(Convert.ToInt32(model.EmployeeID));
                    return(View(editEmployee));
                }
                else
                {
                    model.Email = EmailNew;
                }
                if (!ModelState.IsValid)
                {
                    ViewBag.Title = model.EmployeeID == 0 ? "Create new Employee" : "Edit a Employee";
                    Employee editEmployee = CataLogBLL.GetEmployee(Convert.ToInt32(model.EmployeeID));
                    return(View(editEmployee));
                }

                if (model.EmployeeID == 0)
                {
                    CataLogBLL.AddEmployee(model);
                }
                else
                {
                    CataLogBLL.UpdateEmployee(model);
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message + "" + ex.StackTrace));
            }
        }