Exemplo n.º 1
0
        public async Task <Offer> CreateAsync(Offer offer)
        {
            var offerRecord = _mapper.Map <DataProvider.Models.Offer>(offer);

            await EmbedCityAsync(offerRecord);

            offerRecord.Currency = "EUR";

            var date   = DateTime.Now;
            var number = await _sequenceDataProvider.GetNextOfferSequenceNumberAsync(date);

            offerRecord.SequenceNumber = number;
            var offerNumber = $"{(date.Year + 10).ToString().Substring(2, 2)}/{date.ToString("MM")}/{date.ToString("dd")}/{number.ToString("D2")}";

            offerRecord.Number = offerNumber;

            _context.Offers.Add(offerRecord);
            // EF Core requires to create an order record as well because offer and order share the same underlying SQL table
            var orderRecord = _mapper.Map <DataProvider.Models.Order>(offerRecord);

            _context.Orders.Add(orderRecord);
            await _context.SaveChangesAsync();

            return(_mapper.Map <Offer>(offerRecord));
        }
Exemplo n.º 2
0
        public async Task <Offer> CreateAsync(Offer offer)
        {
            var offerRecord = _mapper.Map <DataProvider.Models.Offer>(offer);

            // offernumber is set on creation and doesn't change afterwards. No matter what happens to the offer date
            var date            = offer.OfferDate == null ? DateTimeOffset.UtcNow.UtcDateTime : (DateTime)offer.OfferDate;
            var offerNumberDate = $"{(date.Year + 10).ToString().Substring(2, 2)}/{date.ToString("MM")}/{date.ToString("dd")}/";
            var sequenceNumber  = await _sequenceDataProvider.GetNextOfferSequenceNumberAsync(offerNumberDate);

            offerRecord.SequenceNumber = sequenceNumber;
            var offerNumber = $"{offerNumberDate}{sequenceNumber.ToString("D2")}";

            offerRecord.Number = offerNumber;

            await EmbedCityAsync(offerRecord);

            offerRecord.Currency = "EUR";

            _context.Offers.Add(offerRecord);
            await _context.SaveChangesAsync();

            // EF Core requires to create an order record as well because offer and order share the same underlying SQL table
            var orderRecord = _mapper.Map <DataProvider.Models.Order>(offerRecord);

            _context.Orders.Add(orderRecord);
            await _context.SaveChangesAsync();

            return(_mapper.Map <Offer>(offerRecord));
        }