public static async Task <Address> Create(Address address, OrderingDbContext context)
        {
            context.Add(address);
            await context.SaveChangesAsync();

            return(address);
        }
 public OrdersController(
     OrderingDbContext dbContext,
     ICurrentUserService currentUser,
     IMapper mapper,
     IBus publisher)
 {
     this.orderingDbContext = dbContext;
     this.currentUser       = currentUser;
     this.mapper            = mapper;
     this.publisher         = publisher;
 }
Exemple #3
0
        public static async Task SetProgress(
            OrderingDbContext context,
            Order order,
            bool catalogueSolutionsViewed,
            bool additionalServicesViewed,
            bool associatedServicesViewed)
        {
            order.Progress.CatalogueSolutionsViewed = catalogueSolutionsViewed;
            order.Progress.AdditionalServicesViewed = additionalServicesViewed;
            order.Progress.AssociatedServicesViewed = associatedServicesViewed;

            context.Update(order);
            await context.SaveChangesAsync();
        }
        protected override async Task Handle(BasketCheckoutMessage request, CancellationToken cancellationToken)
        {
            var order = new Order()
            {
                Id         = Guid.NewGuid().ToDbStringId(),
                Paid       = false,
                Total      = request.BasketTotal,
                PlacedTime = DateTime.Now.ToDbDateTimeString(),
                UserId     = request.UserId
            };

            await using var dbContext = new OrderingDbContext(_dbContextOptions);
            await dbContext.Orders.AddAsync(order, cancellationToken);

            await dbContext.SaveChangesAsync(cancellationToken);
        }
        public static async Task <Order> GetFullOrderAsync(CallOffId callOffId, OrderingDbContext context)
        {
            var fullOrder = await context.Order
                            .Where(o => o.Id == callOffId.Id)
                            .Include(o => o.OrderingParty).ThenInclude(p => p.Address)
                            .Include(o => o.OrderingPartyContact)
                            .Include(o => o.Supplier).ThenInclude(s => s.Address)
                            .Include(o => o.SupplierContact)
                            .Include(o => o.OrderItems).ThenInclude(i => i.CatalogueItem)
                            .Include(o => o.OrderItems).ThenInclude(i => i.OrderItemRecipients).ThenInclude(r => r.Recipient)
                            .Include(o => o.OrderItems).ThenInclude(i => i.PricingUnit)
                            .Include(o => o.Progress)
                            .AsNoTracking()
                            .SingleOrDefaultAsync();

            return(fullOrder);
        }
        public static async Task <Order> CreateOrderAsync(CreateOrderModel model, OrderingDbContext dbContext, User user, string isapiConnectionString)
        {
            var organisationDetails = await Organisation.GetOrganisationById(isapiConnectionString, model.OrganisationId);

            var orderingParty = await dbContext.OrderingParty.FindAsync(model.OrganisationId)
                                ?? new OrderingParty
            {
                Id      = model.OrganisationId,
                OdsCode = organisationDetails.OdsCode,
                Address = AddressHelper.Generate(),
            };

            var order = new OrderBuilder(model.Description, user, orderingParty)
                        .Build();

            dbContext.Add(order);
            await dbContext.SaveChangesAsync();

            return(order);
        }
        public static async Task <OrderItem> CreateOrderItem(
            Order order,
            CatalogueItemType catalogueItemType,
            CataloguePriceType cataloguePriceType,
            ProvisioningType provisioningType,
            OrderingDbContext context,
            string connectionString,
            TimeUnit timeUnit = TimeUnit.PerYear)
        {
            var solution = await SupplierInfo.GetPublishedCatalogueItemsNoTieredAsync(connectionString, order.Supplier.Id, catalogueItemType);

            var selectedItem = RandomInformation.GetRandomItem(solution);

            var catalogueItem = await context.FindAsync <CatalogueItem>(CatalogueItemId.ParseExact(selectedItem.CatalogueItemId))
                                ?? selectedItem.ToDomain();

            var catalogueItemPricingUnit = await GetPricingUnitAsync(provisioningType, connectionString);

            var pricingUnit = await context.FindAsync <PricingUnit>(catalogueItemPricingUnit.Name) ?? catalogueItemPricingUnit;

            var orderItem = new OrderItemBuilder(order.Id)
                            .WithCatalogueItem(catalogueItem)
                            .WithCataloguePriceType(cataloguePriceType)
                            .WithCurrencyCode()
                            .WithDefaultDeliveryDate(DateTime.Today)
                            .WithPrice(0.01M)
                            .WithPricingTimeUnit(timeUnit)
                            .WithProvisioningType(provisioningType)
                            .WithPricingUnit(pricingUnit)
                            .WithEstimationPeriod(timeUnit);

            if (provisioningType == ProvisioningType.OnDemand)
            {
                orderItem.WithEstimationPeriod(timeUnit);
            }

            return(orderItem.Build());
        }
 public ShopCartService(OrderingDbContext db, IMapper mapper) : base(db)
 {
     this.mapper = mapper;
 }
Exemple #9
0
 public BuyerDbBuilder(OrderingDbContext context)
 {
     _context = context;
 }
Exemple #10
0
 public OrderRepositoryBase(
     OrderingDbContext dbContext,
     IExecutionContext currentRequestState)
     : base(dbContext, currentRequestState)
 {
 }
Exemple #11
0
 /// <summary>
 /// 初始化请求管道:事务行为
 /// </summary>
 public TransactionBehavior(OrderingDbContext dbContext, ILogger <TransactionBehavior <TRequest, TResponse> > logger)
 {
     _dbContext = dbContext;
     _logger    = logger;
 }
Exemple #12
0
 /// <summary>
 /// 初始化买家仓储
 /// </summary>
 /// <param name="context">订单DbContext</param>
 public BuyerRepository(OrderingDbContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
 public GenericRepository(OrderingDbContext context)
 {
     _context = context;
 }
 public OrderService(OrderingDbContext db, IBus publisher, ILogger <OrderService> logger)
     : base(db)
 {
     this.publisher = publisher;
     this.logger    = logger;
 }
        public static async Task <OrderItem> AddRecipientToOrderItem(OrderItem orderItem, IEnumerable <OrderItemRecipient> recipients, OrderingDbContext context)
        {
            List <OrderItemRecipient> validatedRecipients = new();

            foreach (var recipient in recipients)
            {
                var existing = await context.ServiceRecipient.FindAsync(recipient.Recipient.OdsCode) ?? recipient.Recipient;

                recipient.Recipient = existing;

                validatedRecipients.Add(recipient);
            }

            orderItem.SetRecipients(validatedRecipients);
            return(orderItem);
        }
        public static async Task <OrderItem> GetOrderItemWithId(Order order, string solutionId, string connectionString, OrderingDbContext context)
        {
            var newPricingUnit = await GetPricingUnitAsync(ProvisioningType.Declarative, connectionString);

            var pricingUnit = await context.FindAsync <PricingUnit>(newPricingUnit.Name) ?? newPricingUnit;

            var selectedItem = (await SupplierInfo.GetPublishedCatalogueItemsNoTieredAsync(connectionString, order.Supplier.Id, CatalogueItemType.Solution))
                               .Single(s => s.CatalogueItemId.ToString().Equals(solutionId));

            var catalogueItem = await context.FindAsync <CatalogueItem>(CatalogueItemId.ParseExact(solutionId))
                                ?? selectedItem.ToDomain();

            var orderItem = new OrderItemBuilder(order.Id)
                            .WithCatalogueItem(catalogueItem)
                            .WithCataloguePriceType(CataloguePriceType.Flat)
                            .WithCurrencyCode()
                            .WithDefaultDeliveryDate(DateTime.Today)
                            .WithPrice(0.01M)
                            .WithPricingTimeUnit(TimeUnit.PerYear)
                            .WithProvisioningType(ProvisioningType.Declarative)
                            .WithPricingUnit(pricingUnit)
                            .WithEstimationPeriod(TimeUnit.PerMonth);

            return(orderItem.Build());
        }
 public OrderingRepository(OrderingDbContext context) : base(context)
 {
     _context = context;
 }
Exemple #18
0
 /// <summary>
 /// 初始化请求管理器
 /// </summary>
 /// <param name="context">订单DbContext</param>
 public RequestManager(OrderingDbContext context)
 {
     _context = context;
 }
Exemple #19
0
 public OrderController(OrderingDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Exemple #20
0
 public BuyersController(OrderingDbContext context)
 {
     _context = context;
 }
Exemple #21
0
    public OrderRepository(OrderingDbContext orderingContext)
    {
        _orderingContext = orderingContext ?? throw new ArgumentNullException(nameof(orderingContext));

        _orderingContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
    }
Exemple #22
0
 public OrderRepository(OrderingDbContext OrderManagementDbContext)
     : base(OrderManagementDbContext)
 {
 }
Exemple #23
0
 public static void SeedDb(OrderingDbContext context)
 {
     new BuyerDbBuilder(context).Create();
     // etc
 }
Exemple #24
0
        public static async Task <IReadOnlyDictionary <string, ServiceRecipient> > AddOrUpdateRecipients(IEnumerable <ServiceRecipient> recipients, OrderingDbContext context)
        {
            var requestRecipients = recipients
                                    .Select(r => new ServiceRecipient(r.OdsCode, r.Name))
                                    .ToDictionary(r => r.OdsCode);

            var existingServiceRecipients = await context.ServiceRecipient
                                            .Where(s => requestRecipients.Keys.Contains(s.OdsCode))
                                            .ToListAsync();

            foreach (var recipient in existingServiceRecipients)
            {
                recipient.Name = requestRecipients[recipient.OdsCode].Name;
            }

            var newServiceRecipients = requestRecipients.Values.Except(existingServiceRecipients).ToList();

            context.ServiceRecipient.AddRange(newServiceRecipients);

            return(existingServiceRecipients.Union(newServiceRecipients).ToDictionary(r => r.OdsCode));
        }
Exemple #25
0
 /// <summary>
 /// 初始化订单仓储
 /// </summary>
 /// <param name="unitOfWork">工作单元</param>
 public OrderRepository(OrderingDbContext context)
 {
     _context = context;
 }
 public ContactDetailsService(OrderingDbContext context)
 {
     this.context = context;
 }