Ejemplo n.º 1
0
 public OrdersController()
 {
     _ordersRepository     = new OrdersRepository();
     _menuItemRepository   = new MenuItemRepository();
     _orderItemsRepository = new OrderItemsRepository();
     _validator            = new OrdersRequestValidator();
 }
Ejemplo n.º 2
0
        public override object OnDelete(Orders request)
        {
            var orderItems = OrderItemsRepository.ForOrderId(new Guid(request.Id)).ToList();

            if (orderItems.Count == 0)
            {
                return new HttpResult
                       {
                           StatusCode        = (HttpStatusCode)422,
                           StatusDescription = "No order found for the given identifier."
                       }
            }
            ;

            // BUG: If more than one order items are contained in the order, it can 't be deleted.
            if (orderItems.Count > 1)
            {
                return new HttpResult {
                           StatusCode = HttpStatusCode.OK
                }
            }
            ;

            orderItems.ForEach(x => OrderItemsRepository.Delete(x.Id.GetValueOrDefault()));

            OrdersRepository.Delete(new Guid(request.Id));

            return(new HttpResult {
                StatusCode = HttpStatusCode.OK
            });
        }
    }
}
Ejemplo n.º 3
0
 public OrderService(CustomerRepository customerRepository, OrderValueRepository orderValueRepository, OrdersRepository ordersRepository, OrderItemsRepository orderItemsRepository)
 {
     this.customerRepository   = customerRepository;
     this.orderValueRepository = orderValueRepository;
     this.ordersRepository     = ordersRepository;
     this.orderItemsRepository = orderItemsRepository;
 }
Ejemplo n.º 4
0
        public JsonResult AjaxCreate(Orders_Items orderItem)
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                bool wasCreated;
                using (OrderItemsRepository itemRep = new OrderItemsRepository(CurrentUser.CompanyId, orderItem.SupplierId))
                {
                    wasCreated = itemRep.Create(orderItem);
                }

                if (wasCreated)
                    return Json(new { success = true, message = String.Empty, newItemId = orderItem.Id }, JsonRequestBehavior.AllowGet);
                else
                    return Json(new { success = false, message = Loc.Dic.error_supplier_item_create_error }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { success = false, message = Loc.Dic.error_no_permission }, JsonRequestBehavior.AllowGet);
            }
        }
Ejemplo n.º 5
0
        public JsonResult GetBySupplier(int?id = null)
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                List <AjaxOrderItem> allItems;
                using (OrderItemsRepository itemRep = new OrderItemsRepository(CurrentUser.CompanyId, id))
                {
                    if (id.HasValue)
                    {
                        allItems = itemRep.GetList().Where(item => item.SupplierId == id && item.CompanyId == CurrentUser.CompanyId).Select(x => new AjaxOrderItem()
                        {
                            Id = x.Id, Title = x.Title, SubTitle = x.SubTitle
                        }).OrderBy(x => x.Title).ToList();
                    }
                    else
                    {
                        allItems = itemRep.GetList().Where(item => item.SupplierId == null && item.CompanyId == CurrentUser.CompanyId).Select(x => new AjaxOrderItem()
                        {
                            Id = x.Id, Title = x.Title, SubTitle = x.SubTitle
                        }).OrderBy(x => x.Title).ToList();
                    }
                }

                if (allItems != null)
                {
                    return(Json(new { gotData = true, data = allItems, message = String.Empty }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { gotData = false, message = Loc.Dic.error_orderitems_get_error }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { gotData = false, message = Loc.Dic.error_no_permission }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 6
0
        public JsonResult AjaxCreate(Orders_Items orderItem)
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                bool wasCreated;
                using (OrderItemsRepository itemRep = new OrderItemsRepository(CurrentUser.CompanyId, orderItem.SupplierId))
                {
                    wasCreated = itemRep.Create(orderItem);
                }

                if (wasCreated)
                {
                    return(Json(new { success = true, message = String.Empty, newItemId = orderItem.Id }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false, message = Loc.Dic.error_supplier_item_create_error }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, message = Loc.Dic.error_no_permission }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 7
0
 public CheckoutService(CustomerRepository customerRepository, OrderItemsRepository orderItemsRepository)
 {
     this.customerRepository   = customerRepository;
     this.orderItemsRepository = orderItemsRepository;
 }
Ejemplo n.º 8
0
 public FinalOrderServices(CustomerRepository customerRepository, OrderItemsRepository orderItemsRepository)
 {
     this.customerRepository   = customerRepository;
     this.orderItemsRepository = orderItemsRepository;
 }
Ejemplo n.º 9
0
 public OrderItemsService(OrderItemsRepository orderItemsRepository)
 {
     this.orderItemsRepository = orderItemsRepository;
 }
Ejemplo n.º 10
0
 public OrderItemsController(IRepository <OrderItems> r)
 {
     repo = (OrderItemsRepository)r;
 }
Ejemplo n.º 11
0
        public JsonResult GetBySupplier(int? id = null)
        {
            if (Authorized(RoleType.OrdersWriter))
            {
                List<AjaxOrderItem> allItems;
                using (OrderItemsRepository itemRep = new OrderItemsRepository(CurrentUser.CompanyId, id))
                {
                    if(id.HasValue)
                        allItems = itemRep.GetList().Where(item => item.SupplierId == id && item.CompanyId == CurrentUser.CompanyId).Select(x => new AjaxOrderItem() { Id = x.Id, Title = x.Title, SubTitle = x.SubTitle }).OrderBy(x => x.Title).ToList();
                    else
                        allItems = itemRep.GetList().Where(item => item.SupplierId == null && item.CompanyId == CurrentUser.CompanyId).Select(x => new AjaxOrderItem() { Id = x.Id, Title = x.Title, SubTitle = x.SubTitle }).OrderBy(x => x.Title).ToList();

                }

                if (allItems != null)
                {
                    return Json(new { gotData = true, data = allItems, message = String.Empty }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(new { gotData = false, message = Loc.Dic.error_orderitems_get_error }, JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                return Json(new { gotData = false, message = Loc.Dic.error_no_permission }, JsonRequestBehavior.AllowGet);
            }
        }