Exemplo n.º 1
0
        public IHttpActionResult PutOrder(int id, Order order)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != order.OrderId)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 2
0
        public IHttpActionResult PostOrder(List<OrdersDTO> orders)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var restaurantId = ((ClaimsIdentity)User.Identity).GetUserId();
            var today = DateTime.Today;
            Order order = new Order();

            order.Status = "Sent";

            order.CreatedBy = restaurantId;
            order.CreatedDate = today;
            order.ModifiedBy = restaurantId;
            order.ModifiedDate = today;
            order.IsActive = true;
            order.RestaurantId = restaurantId;

            decimal totalCost = 0;
            foreach (var ingO in orders ) {

                var IngNotiPost = db.IngNotiPosts.Where(x => x.IngNotiPostId == ingO.ingCostId).FirstOrDefault();

                IngOrder objIngO = new IngOrder();
                objIngO.UnitCostReceived = ingO.unitcost;
                objIngO.IngNotiPost = IngNotiPost ;

                objIngO.CreatedBy = restaurantId;
                objIngO.CreatedDate = today;
                objIngO.ModifiedBy = restaurantId;
                objIngO.ModifiedDate = today;
                objIngO.IsActive = true;
                objIngO.RestaurantId = restaurantId;

                totalCost += ingO.unitcost;
                order.IngOrders.Add(objIngO);
            }
            order.TotalCost = totalCost;

            try
            {
                db.Orders.Add(order);
                db.SaveChanges();
            }
            catch (Exception) {
                throw;
            }

            return CreatedAtRoute("DefaultApi", new { id = order.OrderId }, order);
        }