public Guid AddToBasket(Guid?sessionId, Guid productId) { var newSessionId = sessionId ?? Guid.NewGuid(); var product = _productContext.Products.First(x => x.Id == productId); var session = GetSession(newSessionId); var cartDetails = _cartContext.CartSessionDetails.FirstOrDefault(x => x.ProductId == productId && x.CartSessionId == newSessionId); if (cartDetails == null) { var detail = new CartSessionDetail() { CartSessionId = newSessionId, Id = Guid.NewGuid(), Price = product.Price, ProductId = productId, ProductName = product.Name, Quantity = 1 }; _cartContext.Add(detail); } else { cartDetails.Quantity++; } _cartContext.SaveChanges(); return(newSessionId); }
/// Register public IActionResult Register([Bind("Id,Username,Password,IsAdmin,IsGuest")] User user) { byte[] data = System.Text.Encoding.ASCII.GetBytes(user.Password); data = new System.Security.Cryptography.SHA256Managed().ComputeHash(data); user.Password = System.Text.Encoding.ASCII.GetString(data); _context.Add(user); _context.SaveChanges(); return(View("RegisterLoginView")); }
public int MakeOrder(string userid) { Order order = new Order(); order.CustomerId = userid; order.OrderDate = DateTime.Now; dbcontext.Add(order); int count = dbcontext.SaveChanges(); return(count); }
////////////////////////////////////////////////////////////// /// Client Calls ////////////////////////////////////////////////////////////// public void AddEntry([Bind("Id,EntryItemId,UserId,Quantity")] CartEntry cartEntry) { if (cartEntry != null) { var dupEntry = _context.CartEntries.SingleOrDefault(e => (e.UserId == cartEntry.UserId && e.EntryItemId == cartEntry.EntryItemId)); if (dupEntry == null) { _context.Add(cartEntry); _context.SaveChanges(); } } }
public async Task <IActionResult> Create([Bind("Id,Name,Description,Price,SalePrice,ImageLOC,InStore")] Item item) { if (ModelState.IsValid) { _context.Add(item); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(item)); }
public async Task <IActionResult> Create([Bind("Id,Name,Code,PercentOff,StartDate,EndDate")] Promotion promotion) { if (ModelState.IsValid) { _context.Add(promotion); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(promotion)); }
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)); }
private Domain.Cart CreateCart(Guid?userId) { var cartToken = Guid.NewGuid(); var cart = new Domain.Cart() { CartAccessToken = cartToken, OwnerUserId = userId }; _cartContext.Add(cart); _cartContext.SaveChanges(); // todo not good return(cart); }
public IActionResult WriteReview(IFormCollection form) { var ReviewerId = TempData["userid"]; Review r = new Review(); r.Id = Guid.NewGuid().ToString(); r.ProductId = form["ProductId"]; r.UserId = form["ReviewerId"]; r.ReviewText = form["ReviewText"]; dbcontext.Add(r); dbcontext.SaveChanges(); return(RedirectToAction("ViewPurchase", "MyPurchase", new { userId = r.UserId })); }
private void HandleExistingCart(CartItem item, CustomerCart cart) { var existingProcut = cart.ExistingItemCart(item); cart.AddItem(item); ValidateCart(cart); if (existingProcut) { _context.Update(cart.GetProductById(item.ProductId)); } else { _context.Add(item); } _context.CustomersCart.Update(cart); }
public string receivecartfromlogout([FromBody] Result result) { dbcontext.Database.EnsureDeleted(); //clears old cart records dbcontext.Database.EnsureCreated(); List <Cart> receivedcart = new List <Cart>(); receivedcart = JsonConvert.DeserializeObject <List <Cart> >(result.Value.ToString()); Cart newcart = new Cart(); foreach (Cart cart in receivedcart) // this adds new data { newcart.Id = Guid.NewGuid().ToString(); newcart.productId = cart.productId; newcart.userId = cart.userId; dbcontext.Add(newcart); dbcontext.SaveChanges(); } return(System.Text.Json.JsonSerializer.Serialize(result)); }
// POST: Carts/Create // To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see http://go.microsoft.com/fwlink/?LinkId=317598. public async Task <IActionResult> Create(string GoodId) { var user = await userManager.GetUserAsync(User); // var gd = _Goodcontext.Goods.Where(u => u.Good.Id.Equals(GoodId)); Item good = _itemcontext.Item.Find(GoodId); List <Cart> allcarts = _context.Cart.ToList(); foreach (var t in allcarts) { if (t.ItemId == GoodId && t.UserId == user.Id) { return(NotFound("An item is already in your cart !!!")); } } Console.WriteLine(good); Cart cart = new Cart(); //var user = userManager.GetUserAsync(User).Result; var varUser = _context7.Users.Where(u => u.Email.Equals(User.Identity.Name)); //var user = varUser.FirstOrDefault(); //var user = User.Identity.; // var good = _goodsRepository.AllGoods.FirstOrDefault(p => p.Id == id); if (ModelState.IsValid) { // cart.Good = good; cart.Id = good.Id + "CART" + user.Id; cart.ItemId = good.Id; cart.UserId = user.Id; _context.Add(cart); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(RedirectToAction("Index", cart)); }
public void Add(Cart cart) { _appDbContext.Add(cart); }
public IActionResult Checkout(string userid) { string sessionId = HttpContext.Session.GetString("sessionid"); var items = (from x in dbcontext.Carts where x.UserID == userid || x.SessionId == sessionId select new { ProductId = x.ProductId, Qty = x.Qty }); try { if (items == null) { throw new Exception("There is no items in the cart"); } if (userid == null) { return(RedirectToAction("Login", "Home")); } //Adding new orders Order o = new Order(); string oid = Guid.NewGuid().ToString(); o.Id = oid; o.UserId = userid; o.DateandTime = DateTime.Now; dbcontext.Add(o); foreach (var item in items) { int x = item.Qty; while (x > 0) { Order_Detail od = new Order_Detail(); od.OrderId = oid; od.ActivationCode = Guid.NewGuid().ToString(); od.ProductId = item.ProductId; dbcontext.Add(od); x--; } } //End of updating orders & order_details //remove items from cart upon sucessful transaction of checkout List <Cart> itr = dbcontext.Carts.Where(x => x.UserID == userid).ToList(); foreach (Cart item in itr) { dbcontext.Carts.Remove(item); } dbcontext.SaveChanges(); } catch (Exception) { if (userid == null) { RedirectToAction("ViewProductsWithoutLogin", "Product", new { sessionid = sessionId }); } RedirectToAction("ViewProducts", "Product", new { userId = userid }); } return(RedirectToAction("ViewPurchase", "Mypurchase", new { userId = userid })); }
public void Offer(Cart book) { db.Add(book); }