Пример #1
0
        public ActionResult Edit(Guid id)
        {
            var user = userRepository.GetUserDetailById(id);

            UserVM model = new UserVM();

            if (user != null && user.Count > 0)
            {
                model = user[0];

                var collegeGroupList = new SelectList(collegeGroupRepository.GetCollegeGroups(), "Id", "Name").ToList();
                ViewBag.CollegeGroupList = collegeGroupList;

                var tutorList = new SelectList(userRepository.GetTutorDetailByCollegeGroupId(model.CollegeGroupId.Value), "Id", "Name");
                ViewBag.TutorList = tutorList;

                //Get existing tutor student mapping.
                var tutorStudentMappings = userRepository.GetTutorStudentMappingByTutor(null, model.Id).FirstOrDefault();

                if (tutorStudentMappings != null)
                {
                    model.TutorId = tutorStudentMappings.TutorId;
                }

                //Check Delete Access For Profile Page
                var profilePageAccessRights = userPageRepository.GetUserPageAccessRights(id, "INDIVIDUALPROFILE").FirstOrDefault();

                if (profilePageAccessRights != null)
                {
                    model.IsAllowToDeleteProfile = profilePageAccessRights.IsDelete;
                }
                else
                {
                    model.IsAllowToDeleteProfile = false;
                }

                return(View(model));
            }

            return(RedirectToAction("List"));
        }
Пример #2
0
        public static LoginStatus Login(string email, string password)
        {
            UserRepository         userRepository         = new UserRepository();
            UserRoleRepository     userRoleRepository     = new UserRoleRepository();
            UserPageRepository     userPageRepository     = new UserPageRepository();
            UserGroupRepository    userGroupRepository    = new UserGroupRepository();
            CollegeGroupRepository collegeGroupRepository = new CollegeGroupRepository();

            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
            {
                return(LoginStatus.Failure);
            }

            var user = userRepository.GetUserLogin(email, password);

            if (user == null)
            {
                return(LoginStatus.Failure);
            }
            else
            {
                if (user.IsLoggedIn.HasValue && user.IsLoggedIn.Value == true)
                {
                    return(LoginStatus.AlreadyLoggedIn);
                }
            }

            var userRoles    = userRepository.GetUserRoleByUserId(user.Id, null);
            var userRoleName = GetUserRoleName(userRoles);

            #region Check Student Login Time

            if (userRoles != null && userRoles.Count > 0)
            {
                if (userRoles[0].Code == "STUDENT")
                {
                    var tutorDetails = userRepository.GetTutorStudentMappingByTutor(null, user.Id);
                    if (tutorDetails != null && tutorDetails.Count > 0)
                    {
                        var userLoginTime = userRepository.GetUserLoginTimeByTutor(tutorDetails[0].TutorId).FirstOrDefault();

                        //If time limt set then compare current time and time limit
                        if (userLoginTime != null && !string.IsNullOrWhiteSpace(userLoginTime.ConfigurationType))
                        {
                            if (userLoginTime.ConfigurationType.Trim() == Utility.UserLoginConfigurationType.SET_LIMIT)
                            {
                                var weekDay = (int)DateTime.Now.DayOfWeek;

                                var userLoginTimeConfiguration = userRepository.GetUserLoginTimeConfigurationByTutor(tutorDetails[0].TutorId, weekDay).FirstOrDefault();

                                //Check is login allow for current week day.
                                if (userLoginTimeConfiguration != null)
                                {
                                    if (userLoginTimeConfiguration.IsAllowLogin == true)
                                    {
                                        var loginStartTime = userLoginTimeConfiguration.LoginStartTime.Value;
                                        var loginEndTime   = userLoginTimeConfiguration.LoginEndTime.Value;

                                        var dtLoginStartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, loginStartTime.Hours, loginStartTime.Minutes, loginStartTime.Seconds);
                                        var dtLoginEndTime   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, loginEndTime.Hours, loginEndTime.Minutes, loginEndTime.Seconds);

                                        var currentDateTime = DateTime.Now;

                                        if (!((currentDateTime > dtLoginStartTime) && (currentDateTime < dtLoginEndTime)))
                                        {
                                            return(LoginStatus.InvalidLoginTime);
                                        }
                                        else
                                        {
                                            LogInManager.LoginStartTime = loginStartTime;
                                            LogInManager.LoginEndTime   = loginEndTime;
                                        }
                                    }
                                    else
                                    {
                                        return(LoginStatus.InvalidLoginTime);
                                    }
                                }
                            }
                            else if (userLoginTime.ConfigurationType.Trim() == Utility.UserLoginConfigurationType.RESTRICTED)
                            {
                                return(LoginStatus.InvalidLoginTime);
                            }
                        }
                    }
                }
            }
            #endregion

            var userPageAccessRights = userPageRepository.GetUserPageAccessRights(user.Id, string.Empty);

            var collegeGroup = collegeGroupRepository.GetCollegeGroupById(user.CollegeGroupId.Value);

            if (collegeGroup != null)
            {
                var userGroup = userGroupRepository.GetUserGroupById(collegeGroup.UserGroupId.Value);

                if (userGroup != null)
                {
                    LogInManager.UserGroup  = userGroup;
                    LogInManager.CurrencyId = userGroup.CurrencyId;

                    var currencyInfo = CurrencyManager.GetCurrencyInfoById(userGroup.CurrencyId);
                    if (currencyInfo != null)
                    {
                        LogInManager.CurrencyCode           = currencyInfo.Code;
                        LogInManager.CurrencyConversionRate = currencyInfo.ConversionRate;
                        LogInManager.CurrencySymbol         = currencyInfo.CurrencySymbol;
                    }
                }
            }

            LogInManager.UserName              = user.Name;
            LogInManager.CashierNumber         = user.CashierNumber;
            LogInManager.LoggedInUserId        = user.UserId;
            LogInManager.LoggedInUserSessionId = System.Web.HttpContext.Current.Session.SessionID;
            LogInManager.LoggedInUser          = user;
            LogInManager.UsersRoles            = userRoles;
            LogInManager.UserPageAccessRights  = userPageAccessRights;
            LogInManager.UserRoleName          = userRoleName;
            LogInManager.UserRoleCode          = GetUserRoleCode(userRoles);

            //Update Last LoggedIn Date.
            userRepository.UpdateUsersLastLoginTime(user.Id);

            //Update Flag IsLoggedIn = true
            userRepository.UpdateIsLoggedInFlag(user.Id, true);

            return(LoginStatus.Success);
        }