private async Task <OrderEntity> GetOrderForBuyerToPayOrThrow(CreateCheckoutRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                throw new KnownException("Invalid request model!");
            }

            EnsureBuyerProfile();
            OrdersRepo.ChainQueryable(q => q.Include(o => o.Buyer));
            var order = await OrdersRepo.GetOne(model.OrderId);

            if (order == null)
            {
                throw new KnownException("Comanda nu a fost găsită!");
            }

            if (order.Buyer != CurrentBuyerProfile)
            {
                throw new KnownException("Nu poți plăti această comandă deoarece nu îți aparține!");
            }

            if (order.State == OrderState.Paid || order.State == OrderState.WaitingProcessing)
            {
                throw new KnownException("Această comandă este deja plătită!");
            }

            return(order);
        }
        public async Task <IActionResult> GetOne([FromRoute][Required] string id)
        {
            if (await UserManager.IsInRoleAsync(CurrentUser, "Buyer"))
            {
                EnsureBuyerProfile();
                OrdersRepo.ChainQueryable(q => q.Where(o => o.Buyer == CurrentBuyerProfile));
                var order = await OrdersRepo.GetOne(id);

                if (order == null)
                {
                    return(NotFound());
                }

                return(Ok(Mapper.Map <OrderViewModel>(order)));
            }

            return(NotFound());
        }