Пример #1
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));
        }
Пример #2
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));
            }
        }