Ejemplo 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));
        }
Ejemplo n.º 2
0
        public ActionResult Forget(string email = "", string recaptcha = null)
        {
            if (Request.HttpMethod == "GET")
            {
                return(View());
            }
            //validate captcha
            //var response = Request["g-Recaptch-Response"];
            string secretKey = "6LdQm6kZAAAAAF22PPW7ALrTFfs6BIc8BoIRffUe";
            var    client    = new WebClient();
            var    result    = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secretKey, recaptcha));
            var    obj       = JObject.Parse(result);
            var    status    = (bool)obj.SelectToken("success");

            if (status)
            {
                if (HumanResourceBLL.Employee_CheckMail(email, "Add"))
                {
                    ModelState.AddModelError("", "Email is not exist");
                    return(View());
                }
                string code = Guid.NewGuid().ToString();
                UserAccountBLL.SetCode(email, code, UserAccountTypes.Employee);
                var callbackUrl = Url.Action("ResetPassword", "Account", new { email = email, code = code }, protocol: Request.Url.Scheme);
                Email.sendMail(callbackUrl, email);
                ViewBag.Status = "Sended";
                return(View());
            }
            else
            {
                ViewBag.emai = email;
                ModelState.AddModelError("capchaError", "CAPTCHA was incorrect. Try again");
                return(View());
            }
        }
        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));
            }
        }
Ejemplo n.º 4
0
 public ActionResult Delete(string method = "", int[] employeeIDs = null)
 {
     if (employeeIDs != null)
     {
         HumanResourceBLL.Employee_Delete(employeeIDs);
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult Delete(string method, int[] EmployeeIDs)
 {
     if (EmployeeIDs != null)
     {
         bool delete = HumanResourceBLL.Employee_Delete(EmployeeIDs);
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Khởi tạo kết nối
        /// </summary>
        public static void Initialize()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["LiteCommerce"].ConnectionString;

            CatalogBLL.Initialize(connectionString);
            HumanResourceBLL.Initialize(connectionString);
            AccountBLL.Initialize(connectionString);
            //TODO: Bổ sung khởi tạo các BLL khác khi cần sử dụng :3
        }
Ejemplo n.º 7
0
        public ActionResult Detail(string id = "")
        {
            ViewBag.Title = "Detail Order";
            Order order = SaleManagementBLL.Order_Get(Convert.ToInt32(id));

            ViewData["orderdetail"] = SaleManagementBLL.OrderDetail_Get(Convert.ToInt32(id));
            ViewData["product"]     = CatalogBLL.Product_ListAll();
            ViewData["shipper"]     = CatalogBLL.Shipper_ListAll();
            ViewData["customer"]    = CatalogBLL.Customer_ListAll();
            ViewData["employee"]    = HumanResourceBLL.Employee_ListAll();
            return(View(order));
        }
        public ActionResult CheckEmail(string newEmail = "", string oldEmail = "")
        {
            string rs = "false";

            if (!String.IsNullOrEmpty(newEmail))
            {
                if (HumanResourceBLL.Check_Email(newEmail) && (oldEmail != newEmail))
                {
                    rs = "true";
                }
            }
            return(Content(rs));
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        public static void Initialize()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["LiteCommence"].ConnectionString;

            CatalogBLL.Initialize(connectionString);
            HumanResourceBLL.Initialize(connectionString);
            AccountBLL.Initialize(connectionString);
            UserAccountBLL.Initialize(connectionString);
            SaleManagementBLL.Initialize(connectionString);
            DashboardBLL.Initialize(connectionString);
            //WebSecurity.InitializeDatabaseConnection(connectionString, "TableName", "ColumnId", "ColumnName", autoCreateTables: false);
            //TODO:bổ sùng khởi tạo các BLL khác khi cần sử dụng
        }
Ejemplo n.º 10
0
        // GET: Employee
        public ActionResult Index(int page = 1, string searchValue = "", string country = "")
        {
            var model = new Models.EmployeePaginationResult()
            {
                SearchValue = searchValue,
                Country     = country,
                Page        = page,
                PageSize    = AppSettings.DefaultPagesize,
                RowCount    = HumanResourceBLL.Employee_Count(searchValue, country),
                Data        = HumanResourceBLL.Employee_List(page, AppSettings.DefaultPagesize, searchValue, country)
            };

            return(View(model));
        }
Ejemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ActionResult Index(int page = 1, string searchValue = "")
        {
            HttpCookie requestCookie = Request.Cookies["userInfo"];
            int        idCookie      = Convert.ToInt32(requestCookie["AccountID"]);
            var        model         = new Models.EmployeePaginationResult()
            {
                Page        = page,
                PageSize    = AppSettings.DefaultPageSize,
                RowCount    = HumanResourceBLL.Employee_Count(searchValue, idCookie),
                Data        = HumanResourceBLL.Employee_List(page, AppSettings.DefaultPageSize, searchValue, idCookie),
                SearchValue = searchValue,
            };

            return(View(model));
        }
Ejemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            var model = new DashboardResult
            {
                sumSupplier = CatalogBLL.Supplier_Count(""),
                sumCustomer = CatalogBLL.Customer_Count(""),
                sumShipper  = CatalogBLL.Shipper_Count(""),
                sumCategory = CatalogBLL.Category_Count(""),
                sumProduct  = CatalogBLL.Product_Count("", "", ""),
                sumOrder    = SaleManagementBLL.Order_Count("", ""),
                sumEmployee = HumanResourceBLL.Employee_Count("", "")
            };

            return(View(model));
        }
Ejemplo n.º 13
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));
     }
 }
Ejemplo n.º 14
0
        // GET: Order
        public ActionResult Index(int page = 1, string searchValue = "", string customer = "")
        {
            var model = new Models.OrderPaginationResult()
            {
                Page        = page,
                PageSize    = AppSetting.DefaultPageSize,
                RowCount    = SaleManagementBLL.Order_Count(searchValue, customer),
                Data        = SaleManagementBLL.Order_List(page, AppSetting.DefaultPageSize, searchValue, customer),
                SearchValue = searchValue,
                customer    = customer
            };

            ViewData["shipper"]  = CatalogBLL.Shipper_ListAll();
            ViewData["customer"] = CatalogBLL.Customer_ListAll();
            ViewData["employee"] = HumanResourceBLL.Employee_ListAll();
            return(View(model));
        }
Ejemplo n.º 15
0
 public ActionResult Delete(string method = "", int[] employeeIds = null)
 {
     if (employeeIds != null)
     {
         bool rs = HumanResourceBLL.Employee_Delete(employeeIds);
         if (rs == true)
         {
             TempData["employeeError"] = "<script>alert('Xóa employee thành công!');</script>";
             return(RedirectToAction("Index"));
         }
         else
         {
             TempData["employeeError"] = "<script>alert('Xóa không thành công !');</script>";
             return(RedirectToAction("Index"));
         }
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 16
0
        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"));
                    }
                }
            }
        }
Ejemplo n.º 17
0
        public static List <SelectListItem> ListOfEmployees(bool allowSelectAll = true)
        {
            List <SelectListItem> listEmployees = new List <SelectListItem>();

            if (allowSelectAll)
            {
                listEmployees.Add(new SelectListItem()
                {
                    Value = "", Text = "--- All Employee ---"
                });
            }
            foreach (var item in HumanResourceBLL.Employee_List_Helper())
            {
                listEmployees.Add(new SelectListItem()
                {
                    Value = Convert.ToString(item.EmployeeID), Text = item.LastName
                });
            }
            return(listEmployees);
        }
 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));
     }
 }
Ejemplo n.º 19
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"));
        }
Ejemplo n.º 20
0
        public static List <SelectListItem> Employee(bool allowSelectAll = true)
        {
            List <SelectListItem> list = new List <SelectListItem>();

            if (allowSelectAll)
            {
                list.Add(new SelectListItem()
                {
                    Value = "0", Text = "-- All Employees --"
                });
            }
            foreach (var employee in HumanResourceBLL.Employees_List(1, HumanResourceBLL.Employee_Count("", ""), "", ""))
            {
                list.Add(new SelectListItem()
                {
                    Value = employee.EmployeeID.ToString(),
                    Text  = employee.LastName + " " + employee.FirstName
                });
            }
            return(list);
        }
Ejemplo n.º 21
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"));
        }
Ejemplo n.º 22
0
        public ActionResult Input(Employee data, HttpPostedFileBase files = null)
        {
            if (data.Country == "null")
            {
                ModelState.AddModelError("errorAddr", "Vui lòng chọn quốc gia");
            }
            if (data.Notes == null)
            {
                data.Notes = "";
            }
            if (data.Address == null)
            {
                data.Address = "";
            }
            if (data.HomePhone == null)
            {
                data.HomePhone = "";
            }
            if (data.City == null)
            {
                data.City = "";
            }
            if (data.PhotoPath == null)
            {
                data.PhotoPath = "";
            }
            if (!ModelState.IsValid)
            {
                return(View(data));
            }
            if (string.IsNullOrEmpty(data.FirstName))
            {
                ModelState.AddModelError("ErrorFirstName", "First name is required");
            }
            if (string.IsNullOrEmpty(data.LastName))
            {
                ModelState.AddModelError("ErrorLastName", "Last Name is required");
            }
            if (string.IsNullOrEmpty(data.Password))
            {
                ModelState.AddModelError("ErrorPassword", "Password is required");
            }

            /*if (string.IsNullOrEmpty(data.Email))
             * {
             *  data.Email = "";
             * }
             * if (string.IsNullOrEmpty(data.Address))
             * {
             *  data.Address = "";
             * }
             * if (string.IsNullOrEmpty(data.Notes))
             * {
             *  data.Notes = "";
             * }
             * if (string.IsNullOrEmpty(data.HomePhone))
             * {
             *  data.HomePhone = "";
             * }*/
            if (files != null)
            {
                string get           = DateTime.Now.ToString("ddMMyyyhhmmss");
                string fileExtension = Path.GetExtension(files.FileName);
                string fileName      = get + fileExtension;
                string path          = Path.Combine(Server.MapPath("~/Images"), fileName);
                data.PhotoPath = fileName;
                files.SaveAs(path);
            }
            if (!EncodeMD5.IsMD5(data.Password))
            {
                data.Password = EncodeMD5.GetMD5(data.Password);
            }
            if (data.EmployeeID == 0)
            {
                bool IsEmailExist = AccountBLL.IsEmailExist(data.Email, data.EmployeeID);
                if (IsEmailExist)
                {
                    ModelState.AddModelError("errorEmailDuplicate", "Email đã tồn tại. Vui lòng nhập email khác!");
                    return(View(data));
                }
                else
                {
                    int employeeID = HumanResourceBLL.Employee_Add(data);
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                bool IsEmailExist = AccountBLL.IsEmailExist(data.Email, data.EmployeeID);
                if (IsEmailExist)
                {
                    ModelState.AddModelError("errorEmailDuplicate", "Email đã tồn tại. Vui lòng nhập email khác!");
                    return(View(data));
                }
                else
                {
                    bool updateResult = HumanResourceBLL.Employee_Update(data);
                }
            }
            return(RedirectToAction("Index"));
        }
        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));
            }
        }
Ejemplo n.º 24
0
        public ActionResult Edit(Employee model, HttpPostedFileBase uploadPhoto)
        {
            if (string.IsNullOrEmpty(model.Notes))
            {
                model.Notes = "";
            }
            WebUserData userData = User.GetUserData();

            model.EmployeeID = Convert.ToInt32(userData.UserID);
            string emailCookie = userData.Email;

            if (!HumanResourceBLL.Employee_CheckEmail(model.EmployeeID, model.Email, "update") && (model.Email != emailCookie))
            {
                ModelState.AddModelError("Email", "Email ready exist");
            }
            //Upload ảnh
            if (uploadPhoto != null && uploadPhoto.ContentLength > 0)
            {
                string filePath = Path.Combine(Server.MapPath("~/Images"), uploadPhoto.FileName);
                uploadPhoto.SaveAs(filePath);
                model.PhotoPath = "/Images/" + uploadPhoto.FileName;
            }
            else if (model.PhotoPath == null)
            {
                model.PhotoPath = userData.Photo;
            }
            DateTime hireDate = DateTime.Today;

            if ((hireDate.Year - (model.BirthDate).Year) < 18)
            {
                ModelState.AddModelError("BirthDate", "You must be over 18 years old");
            }
            //Kiểm tra có tồn tại bất kỳ lỗi nào hay không
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                WebUserData userDatas = User.GetUserData();
                string      role      = userDatas.GroupName;
                bool        rs        = UserAccountBLL.Account_Update(model);
                if ((model.Email != userData.Email) || (model.PhotoPath != userData.Photo))
                {
                    //
                    WebUserData cookieData = new WebUserData()
                    {
                        UserID    = model.EmployeeID.ToString(),
                        FullName  = model.LastName + " " + model.FirstName,
                        GroupName = role,
                        SessionID = Session.SessionID,
                        ClientIP  = Request.UserHostAddress,
                        Photo     = model.PhotoPath,
                        Email     = model.Email
                    };
                    FormsAuthentication.SetAuthCookie(cookieData.ToCookieString(), false);
                    return(RedirectToAction("Index"));
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message + ":" + e.StackTrace);
                return(View(model));
            }
        }
Ejemplo n.º 25
0
        public ActionResult Edit(Account model, HttpPostedFileBase uploadPhoto)
        {
            if (string.IsNullOrEmpty(model.Email))
            {
                ModelState.AddModelError("Email", "Email is required");
            }
            if (string.IsNullOrEmpty(model.HomePhone))
            {
                ModelState.AddModelError("HomePhone", "Phone is required");
            }
            if (string.IsNullOrEmpty(model.Address))
            {
                ModelState.AddModelError("Address", "Address is required");
            }
            if (string.IsNullOrEmpty(model.Country))
            {
                ModelState.AddModelError("Country", "Country is required");
            }
            if (string.IsNullOrEmpty(model.City))
            {
                ModelState.AddModelError("City", "City is required");
            }
            if (string.IsNullOrEmpty(model.Notes))
            {
                model.Notes = "";
            }
            HttpCookie requestCookies = Request.Cookies["userInfo"];

            model.AccountID = Convert.ToInt32(requestCookies["AccountID"]);
            string emailCookie = Convert.ToString(requestCookies["Email"]);

            if (!HumanResourceBLL.Employee_CheckEmail(model.AccountID, model.Email, "update") && (model.Email != emailCookie))
            {
                ModelState.AddModelError("Email", "Email ready exist");
            }
            //Upload ảnh
            if (uploadPhoto != null && uploadPhoto.ContentLength > 0)
            {
                string filePath = Path.Combine(Server.MapPath("~/Images"), uploadPhoto.FileName);
                uploadPhoto.SaveAs(filePath);
                model.PhotoPath = "/Images/" + uploadPhoto.FileName;
                requestCookies.Values["PhotoPath"] = Convert.ToString(model.PhotoPath);
                Response.SetCookie(requestCookies);
            }
            else if (model.PhotoPath == null)
            {
                model.PhotoPath = Convert.ToString(requestCookies["PhotoPath"]);
            }
            DateTime hireDate = DateTime.Today;

            if ((hireDate.Year - (model.BirthDate).Year) < 18)
            {
                ModelState.AddModelError("BirthDate", "You must be over 18 years old");
            }
            //Kiểm tra có tồn tại bất kỳ lỗi nào hay không
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                bool rs = AccountBLL.Account_Update(model);
                requestCookies.Values["Email"] = model.Email;
                Response.SetCookie(requestCookies);
                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message + ":" + e.StackTrace);
                return(View(model));
            }
        }
Ejemplo n.º 26
0
        public ActionResult Input(Employee model, HttpPostedFileBase PhotoPath, string PhotoPathDraft)
        {
            try
            {
                // Check Value
                if (string.IsNullOrEmpty(model.LastName))
                {
                    ModelState.AddModelError("LastName", "LastName is required");
                }
                if (string.IsNullOrEmpty(model.FirstName))
                {
                    ModelState.AddModelError("FirstName", "FirstName is required");
                }
                if (string.IsNullOrEmpty(model.Title))
                {
                    ModelState.AddModelError("Title", "Title is required");
                }
                if (string.IsNullOrEmpty(model.LastName))
                {
                    ModelState.AddModelError("LastName", "LastName is required");
                }
                if (string.IsNullOrEmpty(model.Email))
                {
                    ModelState.AddModelError("Email", "Email is required");
                }

                // Kiem tra email tồn tại khi thêm mới
                if (!HumanResourceBLL.Employee_CheckEmail(model.Email, ""))
                {
                    ModelState.AddModelError("Email", "Email is exist");
                }

                if (string.IsNullOrEmpty(model.BirthDate.ToString()))
                {
                    ModelState.AddModelError("BirthDate", "BirthDate is required");
                }

                if (string.IsNullOrEmpty(model.HireDate.ToString()))
                {
                    ModelState.AddModelError("HireDate", "HireDate is required");
                }
                if (string.IsNullOrEmpty(model.Email))
                {
                    ModelState.AddModelError("Email", "Email is required");
                }

                if (string.IsNullOrEmpty(model.Address))
                {
                    model.Address = "";
                }
                if (string.IsNullOrEmpty(model.City))
                {
                    model.City = "";
                }
                if (string.IsNullOrEmpty(model.Country))
                {
                    ModelState.AddModelError("Country", "Country is required");
                }
                if (string.IsNullOrEmpty(model.HomePhone))
                {
                    model.HomePhone = "";
                }
                if (string.IsNullOrEmpty(model.Notes))
                {
                    model.Notes = "";
                }
                if (string.IsNullOrEmpty(model.Password))
                {
                    ModelState.AddModelError("Password", "Password is required");
                }

                if (!ModelState.IsValid)
                {
                    ViewBag.Title = model.EmployeeID == 0 ? "Add New Employee" : "Edit Employee";
                    return(View(model));
                }

                // Upload file
                //TODO :upload image
                if (PhotoPath != null)
                {
                    string FileName = $"{DateTime.Now.Ticks}{Path.GetExtension(PhotoPath.FileName)}";
                    string path     = Path.Combine(Server.MapPath("~/Images"), FileName);
                    PhotoPath.SaveAs(path);
                    model.PhotoPath = FileName;
                }

                if (model.EmployeeID == 0)
                {
                    int employeeID = CatalogBLL.Employee_Add(model);
                }
                else
                {
                    bool updateEmployee = CatalogBLL.Employee_Update(model);
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message + " : " + ex.StackTrace);
                return(View(model));
            }
        }
Ejemplo n.º 27
0
        [HttpPost] //lkhi submit dữ liệu
        public ActionResult Input(Employee model, HttpPostedFileBase file, string[] role = null)
        {
            string groupName = "";

            if (role != null)
            {
                foreach (var eachRole in role)
                {
                    if (groupName == "")
                    {
                        groupName = groupName + eachRole;
                    }
                    else
                    {
                        groupName = groupName + "," + eachRole;
                    }
                }
            }
            model.GroupName = groupName;
            if (string.IsNullOrEmpty(model.LastName))
            {
                ModelState.AddModelError("LastName", "Last Name required");
            }
            if (string.IsNullOrEmpty(model.FirstName))
            {
                ModelState.AddModelError("FirstName", "First Name required");
            }
            if (string.IsNullOrEmpty(model.City))
            {
                model.City = "";
            }
            if (string.IsNullOrEmpty(model.Address))
            {
                model.Address = "";
            }
            if (string.IsNullOrEmpty(model.Title))
            {
                model.Title = "";
            }
            if (string.IsNullOrEmpty(model.Country))
            {
                model.Country = "";
            }
            if (string.IsNullOrEmpty(model.Email))
            {
                model.Email = "";
            }
            if (string.IsNullOrEmpty(model.HomePhone))
            {
                model.HomePhone = "";
            }
            if (string.IsNullOrEmpty(model.Notes))
            {
                model.Notes = "";
            }
            var dateTime        = new DateTime(1900, 01, 01);
            var compareDatetime = DateTime.Compare(model.BirthDate, dateTime);

            if (compareDatetime < 0)
            {
                ModelState.AddModelError("BirthDate", "BirthDate is not format");
                return(View(model));
            }
            compareDatetime = DateTime.Compare(model.HireDate, dateTime);
            if (compareDatetime < 0)
            {
                ModelState.AddModelError("HireDate", "HireDate is not format");
                return(View(model));
            }
            var type = "Add";

            if (model.EmployeeID != 0)
            {
                type = "Edit";
            }
            if (type == "Add")
            {
                if (!HumanResourceBLL.Employee_CheckMail(model.Email, type))
                {
                    ModelState.AddModelError("Email", "Email already exist");
                    return(View(model));
                }
            }
            if (string.IsNullOrEmpty(model.Password))
            {
                ModelState.AddModelError("Password", "Password required");
            }
            var fileName = "";
            var typeFile = "";

            if (file != null)
            {
                //kiểm tra loại của file
                fileName = Path.GetFileName(file.FileName);
                typeFile = fileName.Substring(fileName.IndexOf('.'));
                if (typeFile != ".png" && typeFile != ".jpg" && typeFile != ".jpeg" && typeFile != ".PNG" && typeFile != ".JPG" && typeFile != ".JPEG")
                {
                    ModelState.AddModelError("pathFile", "File is not image");
                    return(View(model));
                }
            }
            else
            {
                model.PhotoPath = "";
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                if (model.EmployeeID == 0)
                {
                    //var path = Path.Combine(Server.MapPath("~/Images"), fileName);
                    //file.SaveAs(path);
                    int supplierId = HumanResourceBLL.Employee_Add(model, file);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    bool updateResult = HumanResourceBLL.Employee_Update(model, file);
                    //set cookie
                    //var nameCoockie = new HttpCookie("name");
                    //nameCoockie.Expires = DateTime.Now.AddDays(-1);
                    //Response.Cookies.Add(nameCoockie);
                    //Response.Cookies["name"].Value = AccountBLL.Account_GetEmployee(account).FirstName + " " + AccountBLL.Account_GetEmployee(account).LastName;
                    //var photoPathCoockie = new HttpCookie("photoPath");
                    //photoPathCoockie.Expires = DateTime.Now.AddDays(-1);
                    //Response.Cookies.Add(photoPathCoockie);
                    //Response.Cookies["photoPath"].Value = AccountBLL.Account_GetEmployee(account).PhotoPath;
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message + ": " + ex.StackTrace);
                return(View());
            }
        }
        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);
            //}
        }
Ejemplo n.º 29
0
 public ActionResult Input(Employee model, HttpPostedFileBase uploadPhoto, string method)
 {
     try
     {
         if (string.IsNullOrEmpty(model.Notes))
         {
             model.Notes = "";
         }
         //Check email
         try
         {
             if (!HumanResourceBLL.Employee_CheckEmail(model.EmployeeID, model.Email, method))
             {
                 ModelState.AddModelError("Email", "Email already exists");
             }
         }
         catch (Exception e)
         {
             ModelState.AddModelError("", e.Message + ":" + e.StackTrace);
         }
         //Upload ảnh
         if (uploadPhoto != null && uploadPhoto.ContentLength > 0)
         {
             string filePath = Path.Combine(Server.MapPath("~/Images"), uploadPhoto.FileName);
             uploadPhoto.SaveAs(filePath);
             model.PhotoPath = "Images/" + uploadPhoto.FileName;
         }
         else if (model.PhotoPath == null)
         {
             model.PhotoPath = "";
         }
         DateTime hireDate = DateTime.Today;
         if ((hireDate.Year - (model.BirthDate).Year) < 18)
         {
             ModelState.AddModelError("BirthDate", "You must be over 18 years old");
         }
         if (!ModelState.IsValid)
         {
             if (model.EmployeeID == 0)
             {
                 ViewBag.Title         = "Add New Employee";
                 ViewBag.ConfirmButton = "Add";
                 ViewBag.Method        = "add";
                 return(View(model));
             }
             else
             {
                 ViewBag.Title         = "Edit Employee";
                 ViewBag.ConfirmButton = "Save";
                 ViewBag.Method        = "update";
                 return(View(model));
             }
         }
         //Đưa dữ liệu vào CSDL
         if (model.EmployeeID == 0)
         {
             int shipperID = HumanResourceBLL.Employee_Add(model);
             return(RedirectToAction("Index"));
         }
         else
         {
             bool rs = HumanResourceBLL.Employee_Update(model);
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception e)
     {
         ModelState.AddModelError("", e.Message + ":" + e.StackTrace);
         return(View(model));
     }
 }