Beispiel #1
0
        public async Task <Cotacao> EnviarOfertaAsync(int idCot, EnviarOfertaDto model)
        {
            var cotacao = await _CotacaoPresist.GetCotacaoByIdAsync(idCot);

            var itensCots = await _CotacaoPresist.GetAllItemCotacaoByIdCotAsync(idCot);

            if (cotacao == null)
            {
                return(null);
            }

            var data = model.DataEntrega.ToString("dd/MM/yyyy");

            cotacao.DataEntrega = data;
            cotacao.status      = 2;
            cotacao.Frete       = model.Frete;
            cotacao.Total       = CalcTotalAsync(itensCots);
            cotacao.Total      += model.Frete;


            FGeralPersist.Update <Cotacao>(cotacao);



            if (await FGeralPersist.SaveChangesAsync())
            {
                return(await _CotacaoPresist.GetCotacaoByIdAsync(idCot));
            }
            return(null);
        }
        public async Task <IActionResult> PutEnviarOferta(int CotacaoId, [FromBody] EnviarOfertaDto model)
        {
            try
            {
                var cotacao = await CotacaoService.EnviarOfertaAsync(CotacaoId, model);

                if (cotacao == null)
                {
                    return(BadRequest("Erro ao tentar Adicionar a cotacao."));
                }
                return(Ok(cotacao));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Erro ao tentar adicionar Cotacao. Erro: {ex.Message}"));
            }
        }