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);

            }
        }
        public ActionResult Order()
        {
            Cart cart = (Cart)Session["Cart"];
            if (cart == null || cart.lineCollection.Count ==0)
            {
                return RedirectToAction("Index", "Home");
            }
            string username = (string)Session["username"];
            Customer cus;

            if (username == null)
            {
                HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                if (authCookie != null)
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
                    username = ticket.Name;
                }
            }
            if (username == null)
            {
                cus = new Customer();
            }
            else
            {
                using (var dbContext = new CocBookEntities())
                {
                    cus = (from c in dbContext.Customers
                           where c.Username == username
                           select c).Single();
                }
            }

            Payment payment = new Payment();
            payment.Cus = cus;
            payment.Cart = cart;
            return View(payment);
        }
        public ActionResult Register(FormCollection form)
        {
            string username = form["user-name"];
            string password = form["pass-word"];
            string fullname = form["full-name"];
            string email = form["user-email"];
            string phone = form["phone"];
            string address = form["address"];
            string district = form["district"];

            Account newAcc = new Account();
            newAcc.Active = true;
            newAcc.Username = username;
            newAcc.Password = password;
            newAcc.RoleID = 1;

            Customer newCus = new Customer();
            newCus.Username = username;
            newCus.Fullname = fullname;
            newCus.Phone = phone;
            newCus.Email = email;
            newCus.District = district;
            newCus.Street = address;
            newCus.City = "HCM";
            newCus.Point = 0;

            using (var dbContext = new CocBookEntities())
            {
                dbContext.Accounts.Add(newAcc);
                dbContext.Customers.Add(newCus);
                dbContext.SaveChanges();
            }

            FormsAuthentication.SetAuthCookie(username, false);
            HttpContext.Session.Add("username", username);

            return RedirectToAction("Profile");
        }
        public ActionResult Order(FormCollection form)
        {
            #region GetInfo
            Cart cart = (Cart)Session["Cart"];
            if (cart == null)
            {
                return RedirectToAction("Index", "Home");
            }
            string username = getUser();
            Customer cus;

            if (username == null)
            {
                cus = new Customer();
                cus.Username = "******";
            }
            else
            {
                using (var dbContext = new CocBookEntities())
                {
                    cus = (from c in dbContext.Customers
                           where c.Username == username
                           select c).Single();
                }
            }
            string fullname = form["full-name"];
            string phone = form["phone"];
            string district = form["district"];
            string address = form["address"];
            string payMethod = form["optPaymentMethod"];
            string speed = form["optSpeed"];
            string comment = form["comment"];
            #endregion
            int oid;
            #region process order
            using (var dbContext = new CocBookEntities())
            {
                Order order = new Order();
                order.Username = cus.Username;
                order.RequestDate = DateTime.Now;
                order.Notes = comment;
                order.Total = cart.GetTotal();
                order.Fullname = fullname;
                order.Phone = phone;
                order.District = district;
                order.Street = address;
                order.City = "HCM";
                order.Elog = "";
                order.GiftCode = "";
                // luu order
                dbContext.Orders.Add(order);
                dbContext.SaveChanges();
                for (int i = 0; i < cart.lineCollection.Count; i++)
                {
                    OrderDetail od = new OrderDetail();
                    od.BookID = cart.lineCollection[i].Book.BookID;
                    od.OrderID = order.OrderID;
                    od.Quantity = cart.lineCollection[i].Quantity;
                    od.Price = cart.lineCollection[i].Book.Price;
                    dbContext.OrderDetails.Add(od);
                }
                dbContext.SaveChanges();
                oid= order.OrderID;
            }

            #endregion
            // xoa gio hang
            cart.Clear();
            Session["cart"] = cart;

            TempData["mess"] = "Xử lý";

            return RedirectToAction("Invoice", "Order", new { id = oid});
        }