Пример #1
0
        public UserService(IRepositoryFactory _repositoryFactory, IHraSessionManager hraSessionManger)
        {
            this._repositoryFactory = _repositoryFactory;
            _hraSessionManager = hraSessionManger;

            sample = new SampleData();
        }
Пример #2
0
        private void SetMenus()
        {
            SampleData entities = new SampleData();

            if (System.Web.HttpContext.Current.User != null && System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                var cuser = System.Web.HttpContext.Current.User;
                if(!string.IsNullOrWhiteSpace(cuser.Identity.Name))
                {
                    var roleId = _applicationContext.ServiceContext.UserService.GetRoleId(cuser.Identity.Name);
                    ViewBag.MenuList = _applicationContext.ServiceContext.UserService.GetMenus(roleId);
                    ViewBag.ExcludeIds = _applicationContext.ServiceContext.UserService.GetExcludeControlIds(roleId);
                }

            }
        }
Пример #3
0
        public ActionResult Index(User user, string action, string ReturnUrl)
        {
            if (action == "Submit")
            {
                bool result = false;
                string msg = string.Empty;
                string fullName = string.Empty;
                if (ModelState.IsValid)
                {
                    Entities.UserManagement.SampleData entities = new SampleData();

                   // result = entities.SUsers.Any(u => u.Username == user.Username);

                    if ( user.Username == null || user.Password == null)
                    {
                        ModelState.AddModelError("", "Please enter Username / Password !");
                        ViewBag.msg = "Error";
                        return View();
                    }
                    if (user.Username == "sadmin")
                    {
                        result = _applicationContext.ServiceContext.AdminService.Login(user.Username, user.Password);
                        fullName = _applicationContext.ServiceContext.AdminService.GetUserName();
                    }
                    else
                    {
                        if (Url.IsLocalUrl(ReturnUrl) && ReturnUrl.Length > 1 && ReturnUrl.StartsWith("/")
                        && !ReturnUrl.StartsWith("//") && !ReturnUrl.StartsWith("/\\"))
                        {
                            string InstitutionId = ReturnUrl.Split('=')[1];
                            Session.Add("InstitutionId", InstitutionId);
                            //ReInitializing Application Context with Institution Details.
                            System.Web.HttpContext.Current.Session["ApplicationContext"] = null;
                            _applicationContext = new ApplicationContext();
                            System.Web.HttpContext.Current.Session["ApplicationContext"] = _applicationContext;

                            result = _applicationContext.ServiceContext.UserService.AuthenticateUser(user.Username, user.Password, out msg, out fullName);
                        }

                    }
                    if (result)
                    {
                        Session["Username"] = fullName;
                        System.Web.HttpContext.Current.Session["ApplicationContext"] = null;
                        Session["InstitutionId"] = null;
                        FormsAuthentication.SetAuthCookie(user.Username, false);

                        if (Url.IsLocalUrl(ReturnUrl) && ReturnUrl.Length > 1 && ReturnUrl.StartsWith("/")
                        && !ReturnUrl.StartsWith("//") && !ReturnUrl.StartsWith("/\\"))
                        {
                            return Redirect(ReturnUrl);
                        }
                        else
                        {
                            return RedirectToAction("ManageInstitution", "Admin");
                        }
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(msg))
                            msg = "Invalid username / Password !";
                        ModelState.AddModelError("", msg);
                        ViewBag.msg = "Error";
                        string tmp = System.Web.HttpContext.Current.Request.RawUrl;
                       // RedirectToAction("Index", "Admin", new { ReturnUrl = ReturnUrl });
                        return View();
                    }
                }
            }
            else
            {
                ModelState.Clear();
                ViewBag.msg = null;
                return View();
            }
            return View();
        }