public async Task <IActionResult> Edit(int id, [Bind("CustomerId,Title,FirstName,LastName,DOB,Phone,Address")] Customer customer)
        {
            if (id != customer.CustomerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.CustomerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("HamperId,HamperName,TotalPrice")] Hamper hamper)
        {
            if (id != hamper.HamperId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(hamper);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HamperExists(hamper.HamperId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(hamper));
        }
        public async Task <IActionResult> Edit(int id, [Bind("HamperCategoryId,HamperCategoryName,Description,Discontinued")] HamperCategory hamperCategory)
        {
            if (id != hamperCategory.HamperCategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(hamperCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HamperCategoryExists(hamperCategory.HamperCategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(hamperCategory));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("CategoryId,CategoryName")] Category category)
        {
            if (id != category.CategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.CategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Exemplo n.º 5
0
        public async Task <Category> UpdateCategory(int id, string categoryName)
        {
            //Search for existing Ctegory Matching this id
            var existingCategory = await _context.Categories.FirstOrDefaultAsync(c => c.CategoryId == id);

            //If something is returned update the category Name
            if (existingCategory != null)
            {
                existingCategory.CategoryName = categoryName;
            }
            //Use context to update the modified record
            _context.Update(existingCategory);
            await _context.SaveChangesAsync();

            return(existingCategory);
        }