Пример #1
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            using (var context = new TackleHackSQLContext())
            {
                var productFeatures = context.ProductFeature.Where(x => x.ProductId == id);
                context.ProductFeature.RemoveRange(productFeatures);
                await context.SaveChangesAsync();

                var productReviews = context.ProductReview.Where(x => x.ProductId == id);
                context.ProductReview.RemoveRange(productReviews);
                await context.SaveChangesAsync();

                var cartItems = context.Cart.Where(x => x.ProductId == id);
                context.Cart.RemoveRange(cartItems);
                await context.SaveChangesAsync();

                var media = context.Media.Where(x => x.ProductId == id);
                context.Media.RemoveRange(media);
                await context.SaveChangesAsync();

                var product = await context.Product.FindAsync(id);

                context.Product.Remove(product);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
        }
        public async Task <IActionResult> Review(String reviewText, String userName, int productId, int productRating)
        {
            using (var context = new TackleHackSQLContext())
            {
                var review = new Review()
                {
                    Text     = reviewText,
                    UserName = userName,
                    DateTime = DateTime.Now,
                    Rating   = productRating
                };
                context.Add(review);
                await context.SaveChangesAsync();

                var productReview = new ProductReview()
                {
                    ReviewId  = review.Id,
                    ProductId = productId
                };
                context.Add(productReview);
                await context.SaveChangesAsync();

                return(RedirectToAction("Details", new { id = productId }));
            }
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Phone,Email")] Vendor vendor)
        {
            if (id != vendor.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    using (var context = new TackleHackSQLContext())
                    {
                        context.Update(vendor);
                        await context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VendorExists(vendor.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vendor));
        }
Пример #4
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            using (var context = new TackleHackSQLContext())
            {
                var vendor = await context.Vendor.FindAsync(id);

                context.Vendor.Remove(vendor);
                await context.SaveChangesAsync();
            }
            return(RedirectToAction(nameof(Index)));
        }
Пример #5
0
        // POST: Cart/Delete/5
        public async Task <IActionResult> Delete(int id)
        {
            using (var context = new TackleHackSQLContext())
            {
                var cart = await context.Cart.FindAsync(id);

                context.Remove(cart);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Phone,Email")] Vendor vendor)
        {
            if (ModelState.IsValid)
            {
                using (var context = new TackleHackSQLContext())
                {
                    context.Add(vendor);
                    await context.SaveChangesAsync();

                    var membership = new Membership()
                    {
                        AccountId = 1,
                        VendorId  = vendor.Id,
                        UserName  = User.Identity.Name
                    };
                    context.Add(membership);
                    await context.SaveChangesAsync();
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vendor));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("Id,ItemNumber,BrandName,ProductName,Description,Sku,Msrp,VendorId")] Product product)
        {
            using (var context = new TackleHackSQLContext())
            {
                if (ModelState.IsValid)
                {
                    context.Add(product);
                    await context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["VendorId"] = new SelectList(await context.Vendor.ToListAsync(), "Id", "Name", product.VendorId);
                return(View(product));
            }
        }
        public async Task <IActionResult> AddToCart(String userName, int productId)
        {
            using (var context = new TackleHackSQLContext())
            {
                var cart = new Cart()
                {
                    UserName  = userName,
                    DateTime  = DateTime.Now,
                    ProductId = productId,
                    Quantity  = 1,
                    Status    = 0
                };
                context.Add(cart);
                await context.SaveChangesAsync();

                return(RedirectToAction("Details", new { id = productId }));
            }
        }
Пример #9
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ItemNumber,BrandName,ProductName,Description,Sku,Msrp,VendorId")] Product product)
        {
            if (id != product.Id)
            {
                return(NotFound());
            }

            using (var context = new TackleHackSQLContext())
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        context.Update(product);
                        await context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ProductExists(product.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }

                var vendorIds = await context.Membership
                                .Where(x => x.UserName == User.Identity.Name)
                                .Select(x => x.VendorId)
                                .ToListAsync();

                var vendors = await context.Vendor
                              .Where(x => vendorIds.Contains(x.Id))
                              .ToListAsync();

                ViewData["VendorId"] = new SelectList(vendors, "Id", "Name", product.VendorId);
                return(View(product));
            }
        }