コード例 #1
0
        public ActionResult Profile()
        {
            using (var dbContext = new CocBookEntities())
            {
                string username = (string)HttpContext.Session["username"];
                if (username == null)
                {
                    HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                    if (authCookie != null)
                    {
                        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
                        username = ticket.Name;
                        HttpContext.Session.Add("username", username);
                    }
                }
                Customer cus = (from c in dbContext.Customers
                                where c.Username == username
                                select c).SingleOrDefault();
                if (cus == null)
                {
                    //return View("Error");
                    cus = new Customer();
                }
                UserProfile ups = new UserProfile();
                ups.CusInfo = cus;
                if (TempData["InfoMess"] != null)
                {
                    ViewBag.InfoMess = TempData["InfoMess"];
                }
                return View(ups);

            }
        }
コード例 #2
0
        public ActionResult UpdateInfo(FormCollection form)
        {
            string fullname = form["full-name"];
            string email = form["user-email"];
            string phone = form["phone"];
            string address = form["address"];
            string district = form["district"];

            if (HttpContext.Session["username"] == null)
            {
                return View("Error");
            }
            using (var dbContext = new CocBookEntities())
            {
                string username = (string)HttpContext.Session["username"];

                Customer cus = (from c in dbContext.Customers
                                where c.Username == username
                                select c).Single();
                cus.Fullname = fullname;
                cus.Phone = phone;
                cus.Email = email;
                cus.District = district;
                cus.Street = address;
                cus.City = "HCM";
                dbContext.SaveChanges();

                UserProfile ups = new UserProfile();
                ups.CusInfo = cus;
                TempData["InfoMess"] = "Thông tin tài khoản đã được cập nhật...";

                return RedirectToAction("Profile", "Customer");

            }
        }