示例#1
0
 public OrderDTO(Order baseOrder)
 {
     this.OrderId = baseOrder.OrderId;
     this.DateCreated = baseOrder.DateCreated;
     this.DateDelivered = baseOrder.DateDelivered;
     this.DateConfirmed = baseOrder.DateConfirmed;
     this.IsConfirmed = baseOrder.IsConfirmed;
     this.IsDelivered = baseOrder.IsDelivered;
     this.User = baseOrder.User;
 }
示例#2
0
        public ActionResult Create(Order order)
        {
            if (ModelState.IsValid)
            {
                db.Orders.Add(order);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(order);
        }
示例#3
0
        public ActionResult EditEmployee(Order order)
        {
            if (ModelState.IsValid)
            {
                var fullOrder = db.Orders.Find(order.OrderId);
                if (order.IsConfirmed == true && fullOrder.IsConfirmed == false)
                {
                    order.DateConfirmed = DateTime.Now;

                }
                else
                {
                    order.DateConfirmed = fullOrder.DateConfirmed;
                }
                if (order.IsDelivered == true && fullOrder.IsDelivered == false)
                {
                    order.DateDelivered = DateTime.Now;

                }
                else
                {
                    order.DateDelivered = fullOrder.DateDelivered;
                }
                order.DateCreated = fullOrder.DateCreated;
                db.Entry(fullOrder).State = EntityState.Detached;
                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("IndexEmployee");
            }
            return View(order);
        }
示例#4
0
 public ActionResult Edit(Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(order);
 }
示例#5
0
        // POST api/Default1
        public HttpResponseMessage PostOrder(IList<CartItem> cartItems)
        {
            if (ModelState.IsValid)
            {
                var user = new UserProfile();
                using (CanteenContext ctx = new CanteenContext())
                {
                    user = (from o in ctx.UserProfiles orderby o.UserId where o.UserName == User.Identity.Name select o).ToList().FirstOrDefault();
                }
                db.Entry(user).State = EntityState.Unchanged;
                var order = new Order()
                {
                    DateConfirmed = DateTime.Now,
                    DateCreated = DateTime.Now,
                    DateDelivered = DateTime.Now,
                    IsConfirmed = false,
                    IsDelivered = false,

                    User = user
                };
                db.Orders.Add(order);
                db.SaveChanges();

                foreach (var i in cartItems)
                {
                    var orderItem = new OrderItem()
                    {
                        MenuItemId = i.Id,
                        OrderId = order.OrderId,
                        Quantity = i.Quantity
                    };

                    db.OrderItems.Add(orderItem);
                }

                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, cartItems);
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
示例#6
0
        // PUT api/Default1/5
        public HttpResponseMessage PutOrder(int id, Order order)
        {
            if (ModelState.IsValid && id == order.OrderId)
            {
                db.Entry(order).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

                return Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }