Пример #1
0
        public ActionResult Index()
        {
            RegisterModel model = new RegisterModel();
            PersonService pservice = new PersonService();
            DepartmentService departmentService = new DepartmentService();

            //model.ListOfPersonName = pservice.GetListOnWorkingOfPersonName(System.DateTime.Now, null, null).ToList();
            model.Departments = departmentService.GetAll().ToList();
            model.ListOfPersonName = pservice.GetListOnWorkingOfPersonDto(System.DateTime.Now, null, null).ToList();

            return View(model);
        }
Пример #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    if (!WebSecurity.UserExists(model.UserName))
                    {
                        AddNewAccount(model);

                        ViewBag.StatusMessage = "Tạo tài khoản thành công.";
                    }
                    else
                        ViewBag.StatusMessage = "Email này đã được sử dụng bởi nhân viên khác.";

                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            PersonService pservice = new PersonService();

            model.ListOfPersonName = pservice.GetListOnWorkingOfPersonDto(System.DateTime.Now, null, null).ToList();

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #3
0
        public ActionResult GetList(JQueryDataTableParamModel param, string reportDate, int departmentId, int filter)
        {
            PersonService pservice = new PersonService();
            IEnumerable<PersonDto> allPersons = new List<PersonDto>();
            int? department = null;
            System.DateTime endedDate;

            if (!System.DateTime.TryParse(reportDate, out endedDate))
                endedDate = System.DateTime.Now;

            if (departmentId != -1)
                department = departmentId;

            switch (filter)
            {
                case 1:
                    if (Roles.IsUserInRole(WebSecurity.CurrentUserName, RoleNames.view1Role))
                        allPersons = pservice.GetListOnWorkingOfPersonDto(System.DateTime.Now, department, pservice.GetPersonIdByUserId(WebSecurity.CurrentUserId));

                    if (Roles.IsUserInRole(WebSecurity.CurrentUserName, RoleNames.view2Role))
                    {
                        Person p = pservice.GetPersonByUserId(WebSecurity.CurrentUserId);
                        if (p != null)
                        {
                            if (p.Department != null)
                            {
                                if (p.Department.Id == departmentId)
                                    allPersons = pservice.GetListOnWorkingOfPersonDto(System.DateTime.Now, departmentId, null);
                            }
                        }
                    }

                    if (Roles.IsUserInRole(WebSecurity.CurrentUserName, RoleNames.view3Role))
                        allPersons = pservice.GetListOnWorkingOfPersonDto(System.DateTime.Now, department, null);

                    break;

                case 2:
                    if (Roles.IsUserInRole(WebSecurity.CurrentUserName, RoleNames.view1Role))
                        allPersons = pservice.GetListAllOfReleasedPersonDto(System.DateTime.Now, department, pservice.GetPersonIdByUserId(WebSecurity.CurrentUserId));

                    if (Roles.IsUserInRole(WebSecurity.CurrentUserName, RoleNames.view2Role))
                    {
                        Person p = pservice.GetPersonByUserId(WebSecurity.CurrentUserId);
                        if (p != null)
                        {
                            if (p.Department != null)
                            {
                                if (p.Department.Id == departmentId)
                                    allPersons = pservice.GetListOnWorkingOfPersonDto(System.DateTime.Now, departmentId, null);
                            }
                        }
                    }

                    if (Roles.IsUserInRole(WebSecurity.CurrentUserName, RoleNames.view3Role))
                        allPersons = pservice.GetListAllOfReleasedPersonDto(System.DateTime.Now, department, null);

                    break;
            }

            IEnumerable<PersonDto> filteredPersons;

            if (!string.IsNullOrEmpty(param.sSearch))
            {
                //Used if particulare columns are filtered
                var lastnameFilter = Convert.ToString(Request["sSearch_0"]);
                var firstnameFilter = Convert.ToString(Request["sSearch_1"]);
                var phongbanFilter = Convert.ToString(Request["sSearch_6"]);

                //Optionally check whether the columns are searchable at all
                var isLastnameSearchable = Convert.ToBoolean(Request["bSearchable_0"]);
                var isFirstnameSearchable = Convert.ToBoolean(Request["bSearchable_1"]);
                var isPhongBanSearchable = Convert.ToBoolean(Request["bSearchable_6"]);

                filteredPersons = allPersons
                   .Where(c => isLastnameSearchable && c.Lastname != null && c.Lastname.ToString().ToLower().Contains(param.sSearch.ToLower())
                            ||
                            isFirstnameSearchable && c.Firstname != null && c.Firstname.ToString().ToLower().Contains(param.sSearch.ToLower())
                           );
            }
            else
            {
                filteredPersons = allPersons;
            }

            var isLastnameSortable = Convert.ToBoolean(Request["bSortable_0"]);
            var isFirstnameSortable = Convert.ToBoolean(Request["bSortable_1"]);
            var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
            Func<PersonDto, string> orderingFunction = (c =>
                                                          sortColumnIndex == 2 && isLastnameSortable ? c.Lastname.ToString() :
                                                          sortColumnIndex == 3 && isFirstnameSortable ? c.Firstname.ToString() :
                                                          "");

            var sortDirection = Request["sSortDir_0"]; // asc or desc
            if (sortDirection == "asc")
                filteredPersons = filteredPersons.OrderBy(orderingFunction);
            else
                filteredPersons = filteredPersons.OrderByDescending(orderingFunction);

            IEnumerable<PersonDto> displayedPersons;

            if (param.iDisplayLength != -1)
                displayedPersons = filteredPersons.Skip(param.iDisplayStart).Take(param.iDisplayLength);
            else
                displayedPersons = filteredPersons;

            var result = from c in displayedPersons
                         select new string[]
                              {
                                  c.Id.ToString(),
                                  c.Lastname,
                                  c.Firstname,
                                  c.GenderName,
                                  c.Birthday,
                                  c.ChucDanhName,
                                  c.DepartmentName,
                                  c.PhoneNumber,
                                  c.Email,
                                  c.RecruitedDate,
                                  c.NgayNghi,
                                  c.Note
                              };

            return Json(new
            {
                sEcho = param.sEcho,
                iTotalRecords = allPersons.Count(),
                iTotalDisplayRecords = filteredPersons.Count(),
                aaData = result
            },
                        JsonRequestBehavior.AllowGet);
        }