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

            return(address);
        }
Beispiel #2
0
        /// <summary>
        /// 请求是否已存在
        /// </summary>
        /// <param name="id">请求Id</param>
        /// <returns>请求是否已存在</returns>
        public async Task CreateRequestForCommandASync <T>(Guid id)
        {
            var exists = await this.ExistAsync(id);

            var request = exists ?
                          throw new OrderingDomainException($"Request with {id} already exists") :
                                new ClientRequest {
                                    Id   = id,
                                    Name = typeof(T).Name,
                                    Time = DateTime.Now
                                };

            _context.Add(request);
            await _context.SaveChangesAsync();
        }
Beispiel #3
0
    public async Task <Order> AddOrGetOrderAsync(Order order)
    {
        _orderingContext.Add(order);

        try
        {
            await _orderingContext.SaveChangesAsync();

            return(order);
        }
        catch (DbUpdateException ex)
            when((ex.InnerException as SqlException)?.Number == 2627)
            {
                return((await GetOrderByIdAsync(order.Id)) !);
            }
    }
        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);
        }