Esempio n. 1
0
        public ActionResult Edit(Guid id)
        {
            var userGroup = userGroupRepository.GetUserGroupById(id);

            UserGroupVM model = new UserGroupVM();

            if (userGroup != null)
            {
                model = userGroup;

                var currencyList = new SelectList(currencyRepository.GetCurrencyInfo()
                                                  .Select(
                                                      m => new SelectListItem()
                {
                    Value = m.Id.ToString(),
                    Text  = (m.Code + " (" + Server.HtmlDecode(m.CurrencySymbol) + ") - " + m.Name)
                }
                                                      ), "Value", "Text").ToList();

                ViewBag.CurrencyList = currencyList;

                return(View(model));
            }

            return(RedirectToAction("List"));
        }
Esempio n. 2
0
        public void TestGetUserGroupById()
        {
            int usergroupId = 1;
            var usergroup   = sut.GetUserGroupById(usergroupId);

            Assert.AreEqual(expected: usergroupId, actual: usergroup.Id);
        }
        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);
        }