コード例 #1
0
        public (bool Allowed, DeliveryState?Target) Apply(DeliveryAction action, ActionContext context)
        {
            var allowed = action == DeliveryAction.Cancel &&
                          _allowedStates.Contains(context.OrderDelivery.State);

            return(allowed, allowed ? DeliveryState.Cancelled : null);
        }
コード例 #2
0
 public void Deliver(IMapleMessage message)
 {
     if (!(message is TMessage))
     {
         throw new ArgumentException("Message is not the correct type"); // TODO translate
     }
     DeliveryAction.Invoke(message as TMessage);
 }
コード例 #3
0
        public (bool Allowed, DeliveryState?Target) Apply(DeliveryAction action, ActionContext context)
        {
            var allowed = action == DeliveryAction.Complete &&
                          context.OrderDelivery.State == DeliveryState.Approved &&
                          context.RequesterRole == RequesterRole.Partner;

            return(allowed, allowed ? DeliveryState.Completed: null);
        }
コード例 #4
0
        public async Task <UberResponse <Delivery> > PostDeliveryAsync(string productId, IList <Item> items, DeliveryAction pickup,
                                                                       DeliveryAction dropoff)
        {
            const string url = "/v1/deliveries";

            Delivery postData = new Delivery
            {
                Items   = items,
                Pickup  = pickup,
                Dropoff = dropoff,
            };

            var content = new StringContent(JsonConvert.SerializeObject(postData), Encoding.UTF8, "application/json");

            return(await PostAsync <Delivery>(url, content));
        }
コード例 #5
0
        public async Task <ActionResult> ChangeDeliveryState(
            [FromRoute] Guid deliveryId, [FromQuery] DeliveryAction action, [FromHeader(Name = "role")] RequesterRole?role)
        {
            if (role == null)
            {
                return(Unauthorized("Role should be defined in header. Values: User | Partner"));
            }

            var response = await _mediator.Send(new ChangeDeliveryStateRequest(deliveryId, action, role.Value));

            if (!response.Failed)
            {
                return(Ok());
            }

            return(response.ErrorReason switch
            {
                OperationErrorReason.ResourceNotFound => NotFound(),
                OperationErrorReason.InvalidOperation => Conflict(),
                _ => StatusCode(StatusCodes.Status500InternalServerError)
            });
コード例 #6
0
        internal static string ToSerializedValue(this DeliveryAction value)
        {
            switch (value)
            {
            case DeliveryAction.Unknown:
                return("Unknown");

            case DeliveryAction.DeliveredAsSpam:
                return("DeliveredAsSpam");

            case DeliveryAction.Delivered:
                return("Delivered");

            case DeliveryAction.Blocked:
                return("Blocked");

            case DeliveryAction.Replaced:
                return("Replaced");
            }
            return(null);
        }
コード例 #7
0
 public bool CanApply(DeliveryAction action, ActionContext context) => action == DeliveryAction.Cancel;
コード例 #8
0
        public (bool Allowed, DeliveryState?Target) ApplyAction(DeliveryAction action, ActionContext context)
        {
            var rule = _rules.FirstOrDefault(r => r.CanApply(action, context));

            return(rule?.Apply(action, context) ?? (false, null));
        }
コード例 #9
0
 public ChangeDeliveryStateRequest(Guid deliveryId, DeliveryAction action, RequesterRole requesterRole)
 {
     DeliveryId    = deliveryId;
     Action        = action;
     RequesterRole = requesterRole;
 }