Beispiel #1
0
        public static List <OrderVM> getUserOrders(IBussinseContext bussinseContext, int?userId, int?role)
        {
            var ordersVM = new List <OrderVM>();

            if (role == (int)Roles.Admin)
            {
                var orders = bussinseContext.OrderBL.GetAll("customer", "product.category");
                foreach (var item in orders)
                {
                    OrderVM vm = item;
                    vm.productName  = item.product.nameAr;
                    vm.categoryName = item.product.category.nameAr;

                    vm.customerName = item.customer.name;
                    vm.productPrice = item.product.price;
                    ordersVM.Add(vm);
                }
            }
            if (role == (int)Roles.Customer)
            {
                var orders = bussinseContext.OrderBL.GetWithInclude(o => o.customerId == userId, "customer", "product.category");
                foreach (var item in orders)
                {
                    OrderVM vm = item;
                    vm.productName  = item.product.nameAr;
                    vm.categoryName = item.product.category.nameAr;
                    vm.customerName = item.customer.name;
                    vm.productPrice = item.product.price;
                    ordersVM.Add(vm);
                }
            }
            return(ordersVM);
        }
Beispiel #2
0
        public static OrderVM getOrderVM(IBussinseContext bussinseContext, int productId)
        {
            var product = bussinseContext.ProductBL.GetWithInclude(p => p.id == productId, "category");
            var OrderVM = new OrderVM();

            OrderVM.productPrice = product[0].price;
            OrderVM.productId    = productId;
            OrderVM.productName  = product[0].nameAr;
            OrderVM.categoryName = product[0].category.nameAr;
            return(OrderVM);
        }
Beispiel #3
0
        public static Order addOrder(IBussinseContext bussinseContext, OrderVM orderVM, int?customerId)
        {
            // place order
            Order order = orderVM;

            order.totalCost   = orderVM.productPrice * orderVM.quntity;
            order.createdDate = DateTime.Now;
            order.customerId  = customerId.Value;
            try
            {
                bussinseContext.OrderBL.AddNew(order);
            }
            catch (Exception e)
            {
                return(null);
            }
            return(order);
        }