public async Task <Customer> PostCustomer(Customer customer)
        {
            rentalDBContext.Customers.Add(customer);
            await rentalDBContext.SaveChangesAsync();

            return(customer);
        }
Example #2
0
        public async Task <IActionResult> PutColor([FromRoute] short id, [FromBody] Color color)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != color.ColorId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #3
0
        public async Task <IActionResult> Create([Bind("ColorId,Name,Code")] Color color)
        {
            if (ModelState.IsValid)
            {
                _context.Add(color);
                await _context.SaveChangesAsync();

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