public ActionResult Edit(staff sta, HttpPostedFileBase photo)
        {
            GroupRoleDao grDao  = new GroupRoleDao();
            StaffDao     staDao = new StaffDao();

            if (ModelState.IsValid)
            {
                try
                {
                    if (photo != null && photo.ContentLength > 0)
                    {
                        staff  exists_sta = staDao.GetById(sta.sta_id);
                        string image      = String.Concat(sta.sta_username, photo.FileName);
                        if (!image.Equals(exists_sta.sta_image))
                        {
                            var image_old = Path.Combine(Server.MapPath("~/Areas/Admins/Content/Photo/Staff/"),
                                                         System.IO.Path.GetFileName(exists_sta.sta_image));
                            if (System.IO.File.Exists(image_old))
                            {
                                System.IO.File.Delete(image_old);
                            }
                            var image_new = Path.Combine(Server.MapPath("~/Areas/Admins/Content/Photo/Staff/"),
                                                         System.IO.Path.GetFileName(image));


                            photo.SaveAs(image_new);
                        }
                        sta.sta_image     = image;
                        sta.sta_update_at = DateTime.Now;
                        staDao.Update(sta);
                    }
                    else
                    {
                        staff exists_sta = staDao.GetById(sta.sta_id);
                        sta.sta_image = exists_sta.sta_image;
                        staDao.Update(sta);
                    }
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(View("Error"));
                }
            }
            else
            {
                ViewBag.lst_gr = grDao.GetAll();
                return(View(sta));
            }
        }
        public JsonResult ExsitsEmail(string sta_email, int?sta_id)
        {
            StaffDao     dao     = new StaffDao();
            List <staff> lts_sta = dao.GetAll();

            if (sta_id != null)
            {
                lts_sta.Remove(dao.GetById(sta_id));
            }
            return(Json(!lts_sta.Any(x => x.sta_email.Trim().ToLower() == sta_email.Trim().ToLower()), JsonRequestBehavior.AllowGet));
        }
        public ActionResult Delete(int id)
        {
            StaffDao dao        = new StaffDao();
            staff    exists_sta = dao.GetById(id);

            var image_old = Path.Combine(Server.MapPath("~/Areas/Admins/Content/Photo/Staff/"),
                                         System.IO.Path.GetFileName(exists_sta.sta_image));

            if (System.IO.File.Exists(image_old))
            {
                System.IO.File.Delete(image_old);
            }
            dao.Delete(id);
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int?id)
        {
            StaffDao staDAo = new StaffDao();

            if (id == null)
            {
                return(View("Error"));
            }
            staff staff = staDAo.GetById(id);

            if (staff == null)
            {
                return(HttpNotFound());
            }
            GroupRoleDao grDao = new GroupRoleDao();

            ViewBag.lst_gr = grDao.GetAll();
            return(View(staff));
        }