public string Register(string username, string password, string name, bool gender, string email, string phone, string address) { if (_context.Accounts.Any(m => m.Username.Equals(username))) { return("UsernameExist"); //return View("UsernameExist"); } Account account = new Account { Username = username, Password = password, Name = name, Gender = gender, Email = email, Phone = phone, Address = address, Active = true, Role = "Customer", BirthDay = DateTime.Now }; _context.Accounts.Add(account); _context.SaveChanges(); HttpContext.Session.Set("Account", account); return("Success"); //return View("Success"); }
public string Checkout() { List <CartViewModel> carts = HttpContext.Session.Get <List <CartViewModel> >("Cart"); if (carts == default) { return("nothing"); } Account account = HttpContext.Session.Get <Account>("Account"); if (account == default) { return("nologin"); } List <BillDetail> billDetails = new List <BillDetail>(); decimal total = 0; foreach (CartViewModel cart in carts) { BillDetail billDetail = new BillDetail { ProductId = cart.IsProduct ? cart.Id : null, ComboId = cart.IsProduct ? null : cart.Id, Price = cart.Price, Quantity = cart.Quantity, }; total += cart.Price * cart.Quantity; billDetails.Add(billDetail); } Bill bill = new Bill { Name = account.Name, Address = account.Address, Phone = account.Phone, Datetime = DateTime.Now, Status = 1, Total = total, BillDetails = billDetails, }; _context.Bills.Add(bill); _context.SaveChanges(); HttpContext.Session.Remove("Cart"); return("success"); }