Пример #1
0
        public async Task <ActionResult <bool> > Post([FromBody] CustomerAddOrUpdateModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            var newCustomer = new Customer
            {
                CustomerID = Guid.NewGuid(),
                Name       = model.Name,
                Email      = model.Email
            };

            DB.Customers.Add(newCustomer);
            await DB.SaveChangesAsync();

            return(true);
        }
Пример #2
0
        public async Task <ActionResult <bool> > Put(Guid id, [FromBody] CustomerAddOrUpdateModel model)
        {
            var customer = await DB.Customers
                           .Where(c => c.CustomerID == id)
                           .FirstOrDefaultAsync();

            if (customer == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }

            customer.Name  = model.Name;
            customer.Email = model.Email;

            await DB.SaveChangesAsync();

            return(true);
        }