Ejemplo n.º 1
0
        public async Task <IHttpActionResult> Put([FromODataUri] int key, Delta <Customer> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var customer = await _db.Customers.FindAsync(key);

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

            patch.Put(customer);

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(key))
                {
                    return(NotFound());
                }
                throw;
            }

            return(Updated(customer));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PutClient(int id, Client client)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != client.Id)
            {
                return(BadRequest());
            }

            _db.Entry(client).State = EntityState.Modified;

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClientExists(id))
                {
                    return(NotFound());
                }
                throw;
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> Post([FromODataUri] int customerId, Order order)
        {
            order.OrderId    = SequentialGuidGenerator.Generate(SequentialGuidType.SequentialAtEnd);
            order.CustomerId = customerId;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _db.Orders.Add(order);
            await _db.SaveChangesAsync();

            return(Created(order));
        }