コード例 #1
0
        public ActionResult SigninOrEdit(SigninUser user)
        {
            bool isSignin = Request.Cookies["user"] == null;

            if (isSignin && DataAccessor.Exists(user.Username, ExistenceCheckOption.ByUsername))
            {
                ModelState.AddModelError("username", "This username is taken. choose an other one.");
            }

            if (isSignin && DataAccessor.Exists(user.Email, ExistenceCheckOption.ByEmail))
            {
                ModelState.AddModelError("email", "This email is already signed in.");
            }

            if (ModelState.IsValid)
            {
                if (isSignin)
                {
                    DataCollector.AddUser(user);
                }
                else
                {
                    DataCollector.UpdateUser(user);
                }

                var u = DataAccessor.GetUser(user.Username, user.Password);

                Response.Cookies["user"]["username"]  = u.Username;
                Response.Cookies["user"]["userId"]    = u.Id.Value.ToString();
                Response.Cookies["user"]["firstName"] = u.FirstName;
                Response.Cookies["user"]["lastname"]  = u.LastNmae;
                Response.Cookies["user"].Expires      = DateTime.Now.AddDays(1);

                var ids = DataAccessor.GetProductsIds(u.Id.Value).Select(p => p.ToString());
                var Ids = new StringBuilder();
                foreach (var item in ids)
                {
                    Ids.Append(item + ",");
                }
                Response.Cookies["cart"]["productsIds"] = Ids.ToString();

                Response.Cookies["cart"].Expires = DateTime.Now.AddDays(-1);

                return(RedirectToRoute(new { Controller = "Home" }));
            }
            ViewBag.IsSignin = isSignin;
            return(View(user));
        }
コード例 #2
0
        public ActionResult loginBox(LoginUser user)
        {
            if (ModelState.IsValid && DataAccessor.Exists(user))
            {
                Response.Cookies["user"]["username"]  = user.Username;
                Response.Cookies["user"]["userId"]    = user.Id.Value.ToString();
                Response.Cookies["user"]["firstName"] = user.FirstName;
                Response.Cookies["user"]["lastname"]  = user.LastNmae;
                Response.Cookies["user"].Expires      = DateTime.Now.AddDays(1);
                var    ids = DataAccessor.GetProductsIds(user.Id.Value).Select(p => p.ToString());
                string Ids = string.Empty;
                foreach (var item in ids)
                {
                    Ids += item + ",";
                }
                Response.Cookies["cart"]["productsIds"] = Ids;
            }
            else
            {
                ModelState.AddModelError("ErMsg", "Username or more password is not correct.");
            }

            return(PartialView(user));
        }
コード例 #3
0
        public ActionResult Login(LoginUser user)
        {
            if (DataAccessor.Exists(user) && ModelState.IsValid)
            {
                Response.Cookies["user"]["username"]  = user.Username;
                Response.Cookies["user"]["userId"]    = user.Id.Value.ToString();
                Response.Cookies["user"]["firstName"] = user.FirstName;
                Response.Cookies["user"]["lastname"]  = user.LastNmae;
                Response.Cookies["user"].Expires      = DateTime.Now.AddDays(1);
                var    ids = DataAccessor.GetProductsIds(user.Id.Value).Select(p => p.ToString());
                string Ids = string.Empty;
                foreach (var item in ids)
                {
                    Ids += item + ",";
                }
                Response.Cookies["cart"]["productsIds"] = Ids;
            }

            else
            {
                ViewBag.LoginMessage = "Username or more password is not correct.";
            }
            return(Index(null));
        }