Example #1
0
        public JsonResult EditDepartment(int id, int languageId)
        {
            try
            {
                var men = _db.Departments.Find(id);
                if (men != null && men.Status != (int)GeneralEnums.StatusEnum.Deleted)
                {
                    var department = LanguageFallbackHelper.GetDepartment(id, languageId);
                    return(Json(department, JsonRequestBehavior.AllowGet));
                }


                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                LogHelper.LogException(User.Identity.Name, ex, "Error While editing Department (Get)");
                return(null);
            }
        }
        public ActionResult Index(int?page, int?typeId, string searchText, int resetTo = 0)
        {
            if (resetTo == 1)
            {
                page = 1;
            }
            ViewBag.SearchText = searchText;
            ViewBag.TypeId     = typeId;
            var citizens = _db.AspNetUserRoles.Where(r => r.AspNetRole.Name == Constants.Roles.Citizen)
                           .Select(r => r.AspNetUser.UserName).ToList();
            var currentLanguageId         = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]);
            var userProfilesForcurrentLan = _db.UserProfileTranslations
                                            .Where(r => (r.LanguageId == currentLanguageId) &&
                                                   r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted).Select(c => c.UserProfileId);
            var userProfiles = _db.UserProfileTranslations
                               .Where(r => (r.IsDefault) &&
                                      r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted &&
                                      !userProfilesForcurrentLan.Contains(r.UserProfileId))
                               .Union(
                _db.UserProfileTranslations
                .Where(r => r.LanguageId == currentLanguageId &&
                       r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted &&
                       userProfilesForcurrentLan.Contains(r.UserProfileId)));

            userProfiles = userProfiles.Where(r => citizens.Contains(r.UserProfile.Username));


            if (typeId != null)
            {
                switch (typeId)
                {
                case (int)GeneralEnums.PersonInformationTypeEnum.Name:
                    userProfiles = userProfiles.Where(r => r.FullName.Contains(searchText));
                    break;

                case (int)GeneralEnums.PersonInformationTypeEnum.Email:
                    userProfiles = userProfiles.Where(r => r.UserProfile.Email.Contains(searchText));
                    break;

                case (int)GeneralEnums.PersonInformationTypeEnum.Mobile:
                    userProfiles = userProfiles.Where(r =>
                                                      r.UserProfile.Mobile.Contains(searchText) ||
                                                      r.UserProfile.PhoneNumber.Contains(searchText) || r.UserProfile.Fax.Contains(searchText));
                    break;

                case (int)GeneralEnums.PersonInformationTypeEnum.Identity:
                    userProfiles = userProfiles.Where(r => r.UserProfile.IdNumber.Contains(searchText));
                    break;
                }
            }

            var result = userProfiles.ToList().Select(x =>
                                                      new ProfileViewModel()
            {
                Id                    = x.UserProfileId,
                LanguageId            = x.LanguageId,
                IdNumber              = x.UserProfile.IdNumber,
                PhoneNumber           = x.UserProfile.PhoneNumber,
                GenderLookupId        = x.UserProfile.GenderLookupId,
                MartialStatusLookupId = x.UserProfile.MartialStatusLookupId,
                FullName              = x.FullName,
                Address               = x.Address,
                Mobile                = x.UserProfile.Mobile,
                Username              = x.UserProfile.Username,
                Email                 = x.UserProfile.Email,
                Fax                   = x.UserProfile.Fax,
                BirthDay              = x.UserProfile.Birthday,
                Status                = x.UserProfile.Status,
                CityId                = x.UserProfile.CityId,
                ProvinceId            = x.UserProfile.ProvinceId,
                RegionId              = x.UserProfile.RegionId,
                LastLogin             = x.UserProfile.LastLogin,
                ManagerId             = x.UserProfile.ManagerId,
                ManagerName           = x.UserProfile?.ManagerId != null ? LanguageFallbackHelper.GetUserProfile((int)x.UserProfile.ManagerId, currentLanguageId)?.FullName : string.Empty,
                Department            = x.UserProfile.DepartmentId,
                DepartmentName        = x.UserProfile?.DepartmentId != null ? LanguageFallbackHelper.GetDepartment((int)x.UserProfile.DepartmentId, currentLanguageId)?.Name : string.Empty,
                PrefferdLanguage      = x.UserProfile.PreferedLanguageId
            });

            var pageSize   = int.Parse(SettingHelper.GetOrCreate(Constants.SystemSettings.ControlPanelPageSize, "10").Value);
            var pageNumber = page ?? 1;

            return(View(result.OrderByDescending(r => r.Id).ToList().ToPagedList(pageNumber, pageSize)));
        }
        public ActionResult Index(int?page, string searchText, int resetTo = 0)
        {
            if (!SessionHelper.CheckSessionCompanyId())
            {
                //logout
            }

            var companyId = SessionHelper.GetCompanyId();

            if (resetTo == 1)
            {
                page = 1;
            }
            var genders = LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.Gender,
                                                                  Request.Cookies["_culture"]);
            var prefferdLanguage = LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.PrefferdLanguage,
                                                                           Request.Cookies["_culture"]);
            var roles           = _db.AspNetRoles.ToList();
            var departments     = LookupHelper.GetDepartments(Request.Cookies["_culture"]);
            var managers        = LookupHelper.GetEmployees(Request.Cookies["_culture"]);
            var martialStatuses =
                LookupHelper.GetLookupDetailsByMasterId((int)GeneralEnums.MasterLookupEnums.MartialStatus,
                                                        Request.Cookies["_culture"]);
            var statuses = LookupHelper.GetStatuses(Request.Cookies["_culture"]);

            ViewBag.Status               = new SelectList(statuses, "Id", "Name");
            ViewBag.RoleList             = new SelectList(roles, "Id", "Name");
            ViewBag.DepartmentsList      = new SelectList(departments, "Id", "Name");
            ViewBag.DepartmentsListEdit  = new SelectList(departments, "Id", "Name");
            ViewBag.StatusEdit           = new SelectList(statuses, "Id", "Name");
            ViewBag.GenderLookupId       = new SelectList(genders, "Id", "Name");
            ViewBag.GenderLookupIdEdit   = new SelectList(genders, "Id", "Name");
            ViewBag.PrefferdLanguage     = new SelectList(prefferdLanguage, "Id", "Name");
            ViewBag.PrefferdLanguageEdit = new SelectList(prefferdLanguage, "Id", "Name");

            ViewBag.ManagerId                 = new SelectList(managers, "Id", "FullName");
            ViewBag.ManagerIdEdit             = new SelectList(managers, "Id", "FullName");
            ViewBag.MartialStatusLookupId     = new SelectList(martialStatuses, "Id", "Name");
            ViewBag.MartialStatusLookupIdEdit = new SelectList(martialStatuses, "Id", "Name");

            var currentLanguageId = CultureHelper.GetCurrentLanguageId(Request.Cookies["_culture"]);

            var userProfilesForcurrentLan = _db.UserProfileTranslations
                                            .Where(r => (r.LanguageId == currentLanguageId) && r.UserProfile.CompanyId == companyId &&
                                                   r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted).Select(c => c.UserProfileId);
            var userProfiles = _db.UserProfileTranslations
                               .Where(r => (r.IsDefault) &&
                                      r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted && !userProfilesForcurrentLan.Contains(r.UserProfileId) && r.UserProfile.CompanyId == companyId)
                               .Union(
                _db.UserProfileTranslations
                .Where(r => r.LanguageId == currentLanguageId && r.UserProfile.CompanyId == companyId && r.UserProfile.Status != (int)GeneralEnums.StatusEnum.Deleted && userProfilesForcurrentLan.Contains(r.UserProfileId)))
                               .ToList();

            if (!searchText.IsNullOrWhiteSpace())
            {
                userProfiles = userProfiles
                               .Where(r =>
                                      (r.FullName.Contains(searchText) || r.FullName.Contains(searchText) ||
                                       r.UserProfile.Mobile.Contains(searchText) || r.UserProfile.PhoneNumber.Contains(searchText))).ToList();
                ViewBag.searchText = searchText;
            }
            var result = userProfiles.ToList().Select(x =>
                                                      new ProfileViewModel()
            {
                Id                    = x.UserProfileId,
                LanguageId            = x.LanguageId,
                IdNumber              = x.UserProfile.IdNumber,
                PhoneNumber           = x.UserProfile.PhoneNumber,
                GenderLookupId        = x.UserProfile.GenderLookupId,
                MartialStatusLookupId = x.UserProfile.MartialStatusLookupId,
                FullName              = x.FullName,
                Address               = x.Address,
                Mobile                = x.UserProfile.Mobile,
                Username              = x.UserProfile.Username,
                Email                 = x.UserProfile.Email,
                Fax                   = x.UserProfile.Fax,
                BirthDay              = x.UserProfile.Birthday,
                Status                = x.UserProfile.Status,
                CityId                = x.UserProfile.CityId,
                ProvinceId            = x.UserProfile.ProvinceId,
                RegionId              = x.UserProfile.RegionId,
                LastLogin             = x.UserProfile.LastLogin,
                ManagerId             = x.UserProfile.ManagerId,
                ManagerName           = x.UserProfile?.ManagerId != null ? LanguageFallbackHelper.GetUserProfile((int)x.UserProfile.ManagerId, currentLanguageId)?.FullName : string.Empty,
                Department            = x.UserProfile.DepartmentId,
                DepartmentName        = x.UserProfile?.DepartmentId != null ? LanguageFallbackHelper.GetDepartment((int)x.UserProfile.DepartmentId, currentLanguageId)?.Name : string.Empty,
                PrefferdLanguage      = x.UserProfile.PreferedLanguageId,
                CompanyId             = x.UserProfile.CompanyId,
            });

            int pageSize   = int.Parse(SettingHelper.GetOrCreate(Core.Constants.SystemSettings.ControlPanelPageSize, "10").Value);
            var pageNumber = (page ?? 1);

            return(View(result.OrderByDescending(r => r.Id).ToList().ToPagedList(pageNumber, pageSize)));
        }