Example #1
0
        //Vue complexe utilisant le modèle OrderDetailsViewModel
        //Permet d'afficher le nom du restaurant de la commande, le numéro de la commande, les plats choisis (bug, 1 seul plat est affiché),
        //la quantité par plats, le prix unitaire d'un plat, l'heure de livraison...
        public ActionResult OrderDetails()
        {
            List <OrderDetailsViewModel> listeOrderDetails = new List <OrderDetailsViewModel>();
            OrderDetailsViewModel        orderDetails      = new OrderDetailsViewModel();

            int idCustomer     = HttpContext.Session.GetInt32("IdCustomer").GetValueOrDefault();
            int idOrder        = HttpContext.Session.GetInt32("IdOrder").GetValueOrDefault();
            int idRestaurant   = HttpContext.Session.GetInt32("IdRestaurant").GetValueOrDefault();
            int idDeliveryTime = HttpContext.Session.GetInt32("Id_Delivery_time").GetValueOrDefault();

            OrderManager.UpdateOrderDeliveryTime(idOrder, idDeliveryTime);

            List <DTO.Order_Dish> listeOrder_Dishes = Order_DishManager.GetAllOrder_Dish(idOrder);

            DTO.Customer   customer   = CustomerManager.GetCustomer(idCustomer);
            DTO.Order      order      = OrderManager.GetOrder(idOrder);
            DTO.Restaurant restaurant = RestaurantManager.GetRestaurant(idRestaurant);


            orderDetails.Customers      = customer;
            orderDetails.Orders         = order;
            orderDetails.Restaurants    = restaurant;
            orderDetails.Cities         = CityManager.GetCity(customer.FK_idCity);
            orderDetails.Delivery_Times = Delivery_TimeManager.GetDelivery_Time(idDeliveryTime);

            foreach (DTO.Order_Dish od in listeOrder_Dishes)
            {
                orderDetails.Order_Dishes = od;
                orderDetails.Dishes       = DishManager.GetDish(od.FK_idDish);
            }

            listeOrderDetails.Add(orderDetails);
            return(View(listeOrderDetails));
        }
Example #2
0
        public static ReturnJasonConstruct <IList <DTO.Order> > GetAllOrders(Guid id)
        {
            ReturnJasonConstruct <IList <DTO.Order> > list = new ReturnJasonConstruct <IList <DTO.Order> >();

            try
            {
                MissFreshEntities db  = new MissFreshEntities();
                string            str = @"select o.id as orderId,o.orderNo as orderNo,o.orderState as orderState,
                                o.totalPrice as totalPrice,o.totalCount as totalCount,
                                o.receiveAddress as receiveAddress,o.tel as tel,o.receivePerson as receivePerson,
                                g.id as goodsId,g.name as name,g.imageName as imageName,od.price as price,
                                od.count as count,od.evaluate as evaluate
                                from Orders o,OrderDetails od,Goods g where o.id = od.orderId and od.goodsId = g.id 
                                and o.accountId='{0}'";
                str = string.Format(str, id);
                DataTable        dt = ExecuteSql(db.Database.Connection.ConnectionString, str);
                List <DTO.Order> ls = new List <DTO.Order>();

                DTO.Order obj     = null;
                Guid      orderId = default(Guid);
                foreach (DataRow item in dt.Rows)
                {
                    if (orderId != (Guid)item["orderId"])
                    {
                        orderId = (Guid)item["orderId"];
                        obj     = new DTO.Order();
                        ls.Add(obj);
                        obj.id              = (Guid)item["orderId"];
                        obj.orderNo         = (long)item["orderNo"];
                        obj.orderState      = (int)item["orderState"];
                        obj.totalPrice      = (decimal)item["totalPrice"];
                        obj.totalCount      = (int)item["totalCount"];
                        obj.receiveAddress  = item["receiveAddress"].ToString();
                        obj.tel             = item["tel"].ToString();
                        obj.receivePerson   = item["receivePerson"].ToString();
                        obj.orderDetailList = new List <DTO.OrderDetail>();
                    }
                    var subObj = new DTO.OrderDetail();
                    obj.orderDetailList.Add(subObj);
                    subObj.id        = (Guid)item["goodsId"];
                    subObj.name      = item["name"].ToString();
                    subObj.imageName = item["imageName"].ToString();
                    subObj.price     = (decimal)item["price"];
                    subObj.count     = (int)item["count"];
                    subObj.evaluate  = (byte)item["evaluate"];
                }

                list.SetDTOObject(ls);
                //string str = string.Format(@"select * from orders o,goods g,orderdetail od from ")
                //var orderList = db.Orders.Where(p=>p.accountId == id).ToList();
                //list.SetDTOObject(orderList.ToDTOs());
                return(list);
            }
            catch (Exception ex)
            {
                list.SetFailedInformation(ex.Message, null);
                return(list);
            }
        }
Example #3
0
        public ReturnJasonConstruct <DTO.Order> Post([FromBody] DTO.Order order)
        {
            order.id = Guid.NewGuid();
            foreach (var item in order.orderDetailList)
            {
                item.id = Guid.NewGuid();
            }

            return(Services.Orders.Create(order));
        }
Example #4
0
        //Lorsque le client choisi un restaurant, l'ordre est directement crée et redirige ensuite vers la liste des plats du restaurant en question
        public ActionResult CreateOrder()
        {
            int idCustomer = HttpContext.Session.GetInt32("IdCustomer").GetValueOrDefault();

            DTO.Order newOrder = new DTO.Order {
                Status = "En cours", FK_idCustomer = idCustomer
            };
            OrderManager.AddOrder(newOrder);

            int idOrder = newOrder.IdOrder;

            HttpContext.Session.SetInt32("IdOrder", idOrder);
            return(RedirectToAction("ListOrder_Dish", "Order_Dish"));
        }
Example #5
0
        public static ReturnJasonConstruct <DTO.Order> Create(DTO.Order order)
        {
            ReturnJasonConstruct <DTO.Order> DTOObject = new ReturnJasonConstruct <DTO.Order>();

            try
            {
                MissFreshEntities db = new MissFreshEntities();
                var model            = order.ToModel();
                model.createTime = DateTime.Now;
                var temp = string.Format("{0:0000}{1:00}{2:00}{3:00}{4:00}{5:00}{6:000}",
                                         model.createTime.Year, model.createTime.Month,
                                         model.createTime.Day, model.createTime.Hour,
                                         model.createTime.Minute, model.createTime.Second,
                                         model.createTime.Millisecond);

                model.orderNo = long.Parse(temp);
                if (order.orderDetailList.Count == 0)
                {
                    DTOObject.SetWarningInformation("订单信息为空.请选择需要购买的菜品.");
                    return(DTOObject);
                }

                //set the first goodsimage for order image
                Guid goodsId = order.orderDetailList[0].id;
                var  goods   = db.Goods.SingleOrDefault(p => p.id == goodsId);
                model.imangeName = goods.imageName;
                foreach (var item in order.orderDetailList)
                {
                    var goodsInfo = db.Goods.Single(p => p.id == item.id);
                    goodsInfo.stock -= item.count;
                    if (goodsInfo.stock < 0)
                    {
                        DTOObject.SetWarningInformation("很抱歉,所选菜品中库存不足.");
                        return(DTOObject);
                    }
                }
                db.Orders.Add(model);
                db.SaveChanges();
                DTOObject.SetDTOObject(model.ToDTO());
                return(DTOObject);
            }
            catch (Exception ex)
            {
                DTOObject.SetFailedInformation(ex.Message, null);
                return(DTOObject);
            }
        }
Example #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String    id        = Request.QueryString["OrderID"].ToString();
            Order_BUS order_BUS = new Order_BUS();

            DTO.Order        order = Order_BUS.GetEntityByID <DTO.Order>(Guid.Parse(id));
            List <DTO.Order> lst   = new List <DTO.Order>();

            lst.Add(order);
            var obj = lst.Select((item, index) =>
            {
                return(new
                {
                    OrderID = item.OrderCode,
                    CustomerName = item.CustomerName,
                    CustomerPhone = item.CustomerPhone,
                    CustomerAddress = item.CustomerAddress,
                    Note = item.Note,
                    IsHidden = (item.IsHidden) ? "checked" : "",
                    PayMethod = (item.PayMethod == 1) ? "Thanh toán tiền mặt" : "Thanh toán qua thẻ tín dụng",
                    CreatedDate = item.CreatedDate.ToString("HH:mm dd/MM/yyyy"),
                    State = (item.State == 1) ? "Đã xử lý" : "Mới",
                    CompletedDate = item.CompletedDate.ToString("HH:mm dd/MM/yyyy"),
                    LinkState = (item.State == 1) ? "" : "<a href = \"updateOrder.aspx?OrderID=" + item.OrderID + "&state=" + item.State + "\"> Chuyển thành đã xử lý </a> "
                });
            });

            DataList1.DataSource = obj;
            DataList1.DataBind();

            GridView2.DataSource = Order_BUS.getOrderDetailById(id);
            GridView2.DataBind();
            Int32 sum = Order_BUS.getSumOrderDetailById(id);


            String s = String.Format("{0:0,0 vnđ}", sum);

            lblSum.Text = "Tổng tiền : " + s;
        }