示例#1
0
        public async Task <Quote> CreateQuote(Quote quote)
        {
            if (quote.TRId != 0)
            {
                await ValidateTR(quote.TRId);

                var trEntity    = mapper.Map <TrEntity>(await QuotesRepository.GetTrAsync(quote.TRId));
                var QuoteEntity = mapper.Map <QuoteEntity>(quote);
                QuoteEntity.Product = null;
                QuoteEntity.Tr      = trEntity;
                QuotesRepository.CreateQuoteTR(QuoteEntity);

                if (await QuotesRepository.SaveChangesAsync())
                {
                    return(mapper.Map <Quote>(QuoteEntity));
                }
                throw new Exception("there where and error with the DB");
            }

            else
            {
                await ValidateProduct(quote.ProductId);

                var QuoteEntity = mapper.Map <QuoteEntity>(quote);
                QuotesRepository.CreateQuote(QuoteEntity);
                if (await QuotesRepository.SaveChangesAsync())
                {
                    return(mapper.Map <Quote>(QuoteEntity));
                }
                throw new Exception("there where and error with the DB");
            }
        }