public async Task <T> AddAsync(T entity) { await _context.Set <T>().AddAsync(entity); await _context.SaveChangesAsync(); return(entity); }
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 <Address> Create(Address address, OrderingDbContext context) { context.Add(address); await context.SaveChangesAsync(); return(address); }
public async Task <ActionResult <int> > CreateAsync([FromBody] CreateBuyerInput input) { var buyer = Buyer.Create(input.UserId, input.Name); await _context.Buyers.AddAsync(buyer); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = buyer.Id }, buyer.Id)); }
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(); }
public async Task <ActionResult <int> > CreateAsync([FromBody] CreateOrderInput input) { var order = Order.Create(input.Address, input.Description, input.BuyerId); foreach (var item in input.Items) { order.Items.Add(OrderItem.Create(item.ProductName, item.UnitPrice, item.Quantity)); } await _context.Orders.AddAsync(order); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetAsync), new { id = order.Id }, order)); }
/// <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(); }
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> 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); }