Пример #1
0
        public IActionResult Login(Login login)
        {
            if (_irepositoryUser.Login(login))
            {
                //User Login

                var userNote = JsonConvert.SerializeObject(_irepositoryUser.GetUserByUserName(login.Username));
                _write.WriteToSession("User", userNote);
                _write.WriteCookies("User", userNote);
                _logger.WriteLog($"user log in : {login.Username}", Catgory.User);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                //Player Not Login
                return(RedirectToAction("index", "Login"));
            }
        }
Пример #2
0
        public IActionResult Index(string sortOrder)
        {
            string user = _read.ReadCookie("User");

            if (user != null)
            {
                //if user exist
                _write.WriteToSession("User", user);
                User CurrectUser = JsonConvert.DeserializeObject <User>(user);
                ViewData["Name"] = CurrectUser.FirstName;
            }

            else
            {
                string UserPP = _read.ReadSession("User");
                if (UserPP != null)
                {
                    User CurrectUser = JsonConvert.DeserializeObject <User>(UserPP);
                    ViewData["Name"] = CurrectUser.FirstName;
                }
            }

            var prods = _repositoryProducts.GetAllProducts();

            switch (sortOrder)
            {
            case "name":
                prods = prods.OrderByDescending(p => p.Title).ToList();
                break;

            case "date":
                prods = prods.OrderBy(p => p.Date).ToList();
                break;

            case "price":
                prods = prods.OrderBy(p => p.Price).ToList();
                break;

            default:
                prods = prods.OrderBy(p => p.Title).ToList();
                break;
            }
            return(View(prods));
        }
Пример #3
0
        public bool UpdateUser(string userPP, Register register)
        {
            User userr = JsonConvert.DeserializeObject <User>(userPP);
            User user  = _context.Users.FirstOrDefault(x => x.UserId == userr.UserId);

            if (user != null)
            {
                user.BirthDate = register.BirthDate;
                user.Email     = register.Email;
                user.FirstName = register.FirstName;
                user.LastName  = register.LastName;

                //check the null of the userName From register
                user.UserName = userr.UserName;
                user.Password = EncryptManager.EncryptPass(register.Password);

                string json = JsonConvert.SerializeObject(user);
                _write.WriteCookies("User", json);
                _write.WriteToSession("User", json);
            }
            return(true);
        }