Beispiel #1
0
        public async Task <IHttpActionResult> PostOrder(Containers.Models.EasyInputs.EasyOrder order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            DB.Order outputOrder = new DB.Order();

            outputOrder = order.ToDBOrder();

            db.Order.Add(order.ToDBOrder());
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = outputOrder.Id }, outputOrder));
        }
Beispiel #2
0
        public async Task <IHttpActionResult> PutOrder(int id, Containers.Models.EasyInputs.EasyOrder order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            DB.Order orderDb = order.ToDBOrder();
            orderDb.Id = id;

            db.Entry(orderDb).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }