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); }
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); }
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); }
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)); }
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) });
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); }
public bool CanApply(DeliveryAction action, ActionContext context) => action == DeliveryAction.Cancel;
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)); }
public ChangeDeliveryStateRequest(Guid deliveryId, DeliveryAction action, RequesterRole requesterRole) { DeliveryId = deliveryId; Action = action; RequesterRole = requesterRole; }