public async Task <IActionResult> Register([Bind("Id,Username,FirstName,LastName,Email,Password,ConfirmPassword")] Account account) { //Setup UserType to Customer, Registration Date. account.Type = UserType.Customer; account.RegistrationDate = DateTime.Now; //(Registration Field, Error Message) //check if Email adress already exists. if (_context.Account.Any(i => i.Email == account.Email)) { ModelState.AddModelError("Email", "Email address already registered to another account."); } //check if UserName already exists. if (_context.Account.Any(i => i.Username == account.Username)) { ModelState.AddModelError("UserName", "That Username is taken, Try another."); } if (ModelState.IsValid) { _context.Add(account); await _context.SaveChangesAsync(); CookieAuthentication(account); return(RedirectToAction("Index", "Home")); } return(View(account)); }
public IActionResult Checkout([Bind("Id,FirstName,LastName,Email,StreetAddress,ZipCode,City,Country,PhoneNumber,CreditCardNum")] Order order) { //if u try to checkout with 0 items var NumOfItems = GetNumOfItems(); var cart = GetShoppingCart(); if (NumOfItems == 0) { return(RedirectToAction(nameof(Index))); } string accountUserName = User.Claims.FirstOrDefault(c => c.Type == "AccountUserName").Value; order.AssociatedAccount = _context.Account.FirstOrDefault(i => i.Username == accountUserName); order.OrderDate = DateTime.Now; order.TotalPrice = GetTotalPrice(); order.Status = OrderStatus.Processing; order.NumOfItems = NumOfItems; if (ModelState.IsValid) { _context.Add(order); //coping ShoppingCartItem into OrderDetail var cartItems = _context.ShoppingCartItem.Where(i => i.AssociatedShoppingCart == cart).Include(p => p.Product); foreach (ShoppingCartItem item in cartItems) { OrderDetail orderItem = new OrderDetail { AssociatedOrder = order, Product = item.Product, UnitPrice = item.UnitPrice, Quantity = item.Quantity }; _context.Add(orderItem); _context.Remove(item); } _context.Remove(cart); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(order)); }
public async Task <IActionResult> Create([Bind("Id,Name,Description,ImageUrl")] Brand brand) { if (ModelState.IsValid) { _context.Add(brand); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(brand)); }
public async Task <IActionResult> Create([Bind("Id,City")] Branch branch) { if (ModelState.IsValid) { _context.Add(branch); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(branch)); }
public async Task <IActionResult> Create([Bind("Id,UnitPrice,Quantity")] OrderDetail orderDetail) { if (ModelState.IsValid) { _context.Add(orderDetail); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(orderDetail)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("Id,Title,Content")] Review review, int productId) { review.Date = DateTime.Now; string accountUserName = User.Claims.FirstOrDefault(c => c.Type == "AccountUserName").Value; review.SentBy = _context.Account.FirstOrDefault(i => i.Username == accountUserName); review.Product = _context.Product.FirstOrDefault(p => p.Id == productId); if (ModelState.IsValid) { _context.Add(review); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(review)); }
public async Task <IActionResult> Create([Bind("Id,Name,Price,Description,ImageUrl,FrontImageUrl,BackImageUrl,UnitsInStock")] Product product, int BrandId, int CategoryId) { product.TotalPurchases = 0; product.Brand = _context.Brand.First(b => b.Id == BrandId); product.Category = _context.Category.First(c => c.Id == CategoryId); if (product.ImageUrl == null) { product.ImageUrl = "/images/Default.png"; } if (product.BackImageUrl == null) { product.BackImageUrl = "/images/Default.png"; } if (product.FrontImageUrl == null) { product.FrontImageUrl = "/images/Default.png"; } if (product.Brand == null) { ModelState.AddModelError("Brand", "Please select a brand."); } if (product.Category == null) { ModelState.AddModelError("Category", "Please select a category."); } if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }