private void buttonReturnBascket_Click(object sender, EventArgs e) { Bascket frm = new Bascket(); frm.Show(); Hide(); }
public async Task <IActionResult> AddToBascket([Bind("ID,Name,Price,Description,Image,Section,DateOfAdd")] Product product, int?Id) { try { var user = await _userManager.GetUserAsync(User); if (user != null && product != null) { product.Reviews = await _context.Reviews.Where(r => r.ProductId == (int)Id).ToListAsync(); foreach (Review review in product.Reviews) { review.User = await _userManager.FindByIdAsync(review.UserId); } var bascket = new Bascket { UserId = user.Id, ProductId = product.ID, BascketPrice = product.Price }; _context.Add(bascket); await _context.SaveChangesAsync(); } } catch (DbUpdateException) { Console.WriteLine("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View("Details", product)); }
public IActionResult Buy(Guid userId, Guid productId) { var product = dbContext.Products.FirstOrDefault(pr => pr.Id == productId); var newBascet = new Bascket() { Id = Guid.NewGuid(), DateRegister = DateTime.Now, // Number = ProductId = product.Id }; var count = 0; if (userId != Guid.Empty) { var user = dbContext.Userss.FirstOrDefault(user => user.Id == userId); newBascet.UserId = user.Id; this.dbContext.Basckets.Add(newBascet); this.dbContext.SaveChanges(); var userBaskets = this.dbContext.Basckets .Include(b => b.Product) .Where(b => b.UserId == userId).ToList(); count = userBaskets.Count; } else { //this.dbContext.Basckets.Add(newBascet); //this.dbContext.SaveChanges(); } return(new JsonResult(new { Count = count, Message = "Додано успішно" })); }