Esempio n. 1
0
        public async Task <IActionResult> PutCategory([FromRoute] int id, [FromBody] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != category.CategoryId)
            {
                return(BadRequest());
            }

            _context.Entry(category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("CustomerId,Title,FirstName,LastName,DOB,Phone,Address")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("HamperId,HamperName,TotalPrice")] Hamper hamper)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hamper);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hamper));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("CategoryId,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <IActionResult> Create([Bind("HamperCategoryId,HamperCategoryName,Description,Discontinued")] HamperCategory hamperCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hamperCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hamperCategory));
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("ProductName,ProductCode,Price,Discontinued,Productdescription")] ProductCreateViewModel productCreateViewModel)
        {
            if (ModelState.IsValid)
            {
                var Newproduct = new Product
                {
                    ProductName        = productCreateViewModel.ProductName,
                    ProductCode        = productCreateViewModel.ProductCode,
                    Price              = productCreateViewModel.Price,
                    Discontinued       = productCreateViewModel.Discontinued,
                    Productdescription = productCreateViewModel.Productdescription
                };
                _context.Products.Add(Newproduct);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(productCreateViewModel));
        }