public async Task <IActionResult> UpdateQuantity(string customerId, string name, [FromBody] UpdateQuantityDto item)
        {
            if (item == null)
            {
                return(ResponseMessage.BadRequest(Status.UnexpectedError, UnexpectedError));
            }

            var validator = new UpdateQuantityValidator();
            var results   = validator.Validate(item);

            if (!results.IsValid)
            {
                var error = results.Errors.FirstOrDefault();
                return(ResponseMessage.BadRequest(error.ErrorCode, error.ErrorMessage));
            }

            var actor = (PID)shoppingListsActorProvider.ActorInstance;

            var @event = await actor.RequestAsync <ShoppingListEvent>(new UpdateQuantity(customerId, name, item.Quantity));

            switch (@event.Status)
            {
            case Status.QuantityUpdated: return(ResponseMessage.Ok(@event.Status, QuantityUpdated));

            case Status.ItemNotFound: return(ResponseMessage.NotFound(@event.Status, ItemNotFound));

            default: return(ResponseMessage.BadRequest(@event.Status, UnexpectedError));
            }
        }
        public async Task <IActionResult> Post(string customerId, [FromBody] AddItemDto item)
        {
            if (item == null)
            {
                return(ResponseMessage.BadRequest(Status.UnexpectedError, UnexpectedError));
            }

            var validator = new AddItemValidator();
            var results   = validator.Validate(item);

            if (!results.IsValid)
            {
                var error = results.Errors.FirstOrDefault();
                return(ResponseMessage.BadRequest(error.ErrorCode, error.ErrorMessage));
            }

            var actor = (PID)shoppingListsActorProvider.ActorInstance;

            var @event = await actor.RequestAsync <ShoppingListEvent>(new AddItem(customerId, item.Name, item.Quantity));

            switch (@event.Status)
            {
            case Status.ItemAdded: return(ResponseMessage.CreatedAtAction("Get", "ShoppingLists", new { name = item.Name }, @event.Status, ItemAdded));

            case Status.QuantityUpdated: return(ResponseMessage.Ok(@event.Status, ItemUpdatedWithNewQuantity));

            default: return(ResponseMessage.BadRequest(@event.Status, UnexpectedError));
            }
        }
        public async Task <IActionResult> Delete(string customerId, string name)
        {
            var actor = (PID)shoppingListsActorProvider.ActorInstance;

            var @event = await actor.RequestAsync <ShoppingListEvent>(new RemoveItem(customerId, name));

            switch (@event.Status)
            {
            case Status.ItemRemoved: return(ResponseMessage.Ok(@event.Status, ItemRemoved));

            case Status.ItemNotFound: return(ResponseMessage.NotFound(@event.Status, ItemNotFound));

            default: return(ResponseMessage.BadRequest(@event.Status, UnexpectedError));
            }
        }
        public async Task <IActionResult> Get(string customerId, string name)
        {
            var actor = (PID)shoppingListsActorProvider.ActorInstance;

            var @event = await actor.RequestAsync <ShoppingListEvent>(new GetItem(customerId, name));

            switch (@event.Status)
            {
            case Status.ItemFound: return(Ok(new ShoppingListItemDto {
                    Name = ((ItemRetrieved)@event).Name, Quantity = ((ItemRetrieved)@event).Quantity
                }));

            case Status.ItemNotFound: return(ResponseMessage.NotFound(@event.Status, ItemNotFound));

            default: return(ResponseMessage.BadRequest(@event.Status, UnexpectedError));
            }
        }