Example #1
0
 public Order(
     Cart cart,
     PaymentType paymentType,
     Delivery delivery)
 {
     Cart        = cart;
     PaymentType = paymentType;
     Delivery    = delivery;
     _orderStage = OrderStage.SuccessfullyMade;
     TotalPrice  = CalculateTotalPrice();
 }
Example #2
0
        private void ValidateReason(OrderStage stage, OrderStageReason?reason)
        {
            switch (stage)
            {
            case OrderStage.Accepted:
            case OrderStage.Fulfilled:
            case OrderStage.Pending:
                if (!reason.HasValue)
                {
                    break;
                }
                else
                {
                    throw new InvalidEnumArgumentException("Invalid reason set for order stage. Reason should be empty.");
                }

            case OrderStage.Failed:
                if (reason == OrderStageReason.FailedPaymentDeclined ||
                    reason == OrderStageReason.FailedSystemError ||
                    reason == OrderStageReason.FailedSellerRejected)
                {
                    break;
                }
                else
                {
                    throw new InvalidEnumArgumentException("Invalid reason set for Failed order stage");
                }

            case OrderStage.Cancelled:
                if (reason == OrderStageReason.CancelledBuyer ||
                    reason == OrderStageReason.CancelledMerchant ||
                    reason == OrderStageReason.CancelledRavelin ||
                    reason == OrderStageReason.CancelledSeller)
                {
                    break;
                }
                else
                {
                    throw new InvalidEnumArgumentException("Invalid reason set for Cancelled order stage");
                }

            case OrderStage.Refunded:
                if (reason == OrderStageReason.RefundedReturned ||
                    reason == OrderStageReason.RefundedComplaint)
                {
                    break;
                }
                else
                {
                    throw new InvalidEnumArgumentException("Invalid reason set for Refunded order stage");
                }
            }
        }
Example #3
0
        public static string GetOrderStage(OrderStage value)
        {
            switch (value)
            {
            case OrderStage.Close:
                return(Constants.OrderStage.Close);

            case OrderStage.Open:
                return(Constants.OrderStage.Open);
            }

            throw new ArgumentOutOfRangeException("value");
        }
Example #4
0
        public void should_serialize_deserialize_order_status(OrderStage stage, OrderStageReason?reason, string expectedReason)
        {
            var orderStatus = new OrderStatus(stage, reason)
            {
                Actor = "buyer"
            };
            var ser = JsonConvert.SerializeObject(orderStatus, serializerSettings);
            var des = JsonConvert.DeserializeObject <OrderStatus>(ser, serializerSettings);

            if (reason.HasValue)
            {
                ser.Contains($"\"reason\": \"{expectedReason}\"").Should().BeTrue();
                des.Reason.Should().Be(reason);
            }

            des.Should().NotBeNull();
            des.Actor.Should().Be("buyer");
        }
Example #5
0
        public async Task <PagedList <OrderViewModel> > GetOrdersAsync(OrderStage orderStage, PagingParameters pagingParameters)
        {
            var userId      = Guid.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value);
            var orderStatus = GetStageOrderStatus(orderStage);

            var queryableOrders = from o in _dbContext.Orders
                                  where orderStatus.Contains(o.OrderStatus) &&
                                  (o.User1Id == userId || o.User2Id == userId)
                                  orderby o.UpdatedTime descending
                                  select o;

            var queryableDto = GetOrderViewModels(queryableOrders, userId);

            var pagedDto = await PagedList <OrderViewModel> .ToPagedListAsync(queryableDto, pagingParameters);

            pagedDto.ForEach(o => o.SetAttachmentProperties(_logger));

            return(pagedDto);
        }
Example #6
0
        private string GetStatusSql(OrderStage orderStage)
        {
            var sqlBuilder = new StringBuilder("(");
            var i          = 0;
            var status     = GetStageOrderStatus(orderStage);

            status.ForEach(s =>
            {
                sqlBuilder.Append((int)s);
                if (i < status.Count - 1)
                {
                    sqlBuilder.Append(", ");
                }
                i++;
            });

            sqlBuilder.Append(")");

            return(sqlBuilder.ToString());
        }
Example #7
0
        private List <OrderStatus> GetStageOrderStatus(OrderStage orderStage)
        {
            var status = new List <OrderStatus>();

            if (orderStage == OrderStage.Shooting)
            {
                status = new List <OrderStatus>
                {
                    OrderStatus.WaitingForShooting
                };
            }
            else if (orderStage == OrderStage.Selection)
            {
                status = new List <OrderStatus>
                {
                    OrderStatus.WaitingForUploadOriginal,
                    OrderStatus.WaitingForSelection
                };
            }
            else if (orderStage == OrderStage.Production)
            {
                status = new List <OrderStatus>
                {
                    OrderStatus.WaitingForUploadProcessed,
                    OrderStatus.WaitingForCheck
                };
            }
            else if (orderStage == OrderStage.Finished)
            {
                status = new List <OrderStatus>
                {
                    OrderStatus.Finished,
                    OrderStatus.Canceled,
                    OrderStatus.Rejected
                };
            }

            return(status);
        }
Example #8
0
 public OrderStatus(OrderStage stage, OrderStageReason?reason = null)
 {
     ValidateReason(stage, reason);
     Stage  = stage;
     Reason = reason;
 }
Example #9
0
 private string GetCountSql(OrderStage orderStage)
 {
     return($"isnull(sum(case when OrderStatus in {GetStatusSql(orderStage)} then 1 else 0 end), 0)");
 }