Exemplo n.º 1
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            TaiKhoan user = new TaiKhoan()
            {
                Email = model.Email, Pass = model.Password
            };

            user = Reporsitory.GetUserDetails(user);

            Session["User"] = user;
            if (user != null)
            {
                FormsAuthentication.SetAuthCookie(model.Email, false);
                var    authTicket      = new FormsAuthenticationTicket(2, user.Email, DateTime.Now, DateTime.Now.AddMinutes(20), false, user.Roles);
                string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
                var    authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                HttpContext.Response.Cookies.Add(authCookie);
                FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe);
                switch (user.Roles)
                {
                case "Admin":
                    return(RedirectToAction("TrangChủ", "Home"));

                case "PM":
                    return(RedirectToAction("TrangNhânViên", "NVs"));

                case "AM":
                    return(RedirectToAction("QuảnLýHóaĐơn", "HDs"));

                case "TT":
                    return(RedirectToAction("TrangPhòng", "Phongs"));

                case "KT":
                    return(RedirectToAction("QuảnLýHóaĐơn", "HDs"));

                default:
                    return(RedirectToAction("TrangChủ", "Home"));
                }
            }

            else
            {
                ModelState.AddModelError("", "Sai mật khẩu hoặc password.");
                //ViewData["LỗiĐăngNhập"] = "Bạn phải đăng nhập mới vào được trang này";
                //ViewData.Add("RedirectReason", "Unauthorized");
                return(View(model));
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //Creates a instance of MockDataProvider so we can access the functions in it
            MockDataProvider dataProvider = new MockDataProvider();

            //Create a instance of Reporsitory so we can call the database function
            Reporsitory executor = new Reporsitory();

            //First it gets the results from dataProvider, and saves it all in the database.
            executor.Save((dataProvider.GetPeople(99)));
            //Calls a function to print all persons to the console
            PrintAll(executor.GetAll());
            //Wait for user to press any key on the keyboard
            Console.ReadKey();
        }
        public void List_WithValidCount_DB()
        {
            //arrange
            int ammount                 = 5;
            MockDataProvider data       = new MockDataProvider();
            Reporsitory      executor   = new Reporsitory();
            List <Person>    personList = new List <Person>();
            int expectedAmmount         = 0;

            //act
            personList      = data.GetPeople(ammount);
            expectedAmmount = personList.Count;
            executor.Save(personList);
            int actualAmmount = executor.GetAll().Count;

            //assert
            Assert.AreEqual(expectedAmmount, actualAmmount);
        }
Exemplo n.º 4
0
 public VehicleModelGenericReporsitory(Reporsitory reporsitory)
 {
     _reporsitory = reporsitory;
 }