Esempio n. 1
0
        public Pedido CadastrarPedido(Lanche lanche, List <ComplementoDomainModel> complementos)
        {
            try
            {
                _unitOfWork.BeginTransaction();

                //Todo Aplicar regras para salvar Pedido
                var    inflacao     = Convert.ToDecimal(_parametroRepository.GetParametroById((long)ParametroEnum.Inflacao).Valor);
                Lanche lancheResult = _lancheRepository.GetLancheById(lanche.IdLanche);

                List <ComplementoDomainModel> ingredientesTotal = new List <ComplementoDomainModel>();

                ingredientesTotal.AddRange(lancheResult.LancheIngredientes.Select(x => new ComplementoDomainModel
                {
                    IdComplemento = x.Ingrediente.IdIngrediente,
                    Valor         = (x.Ingrediente.Valor) + (x.Ingrediente.Valor * inflacao / 100),
                }));

                ingredientesTotal.AddRange(complementos.Where(x => x.Quantidade > 0));



                var resultPedido = _pedidoRepository.SavePedido(new Pedido
                {
                    DataPedido     = DateTime.Now,
                    NumeroPedido   = new Random().Next(1, 999),
                    IdStatusPedido = (int)StatusPedidoEnum.Efetuado,
                    ValorFinal     = EfetuarSomaValorPedido(ingredientesTotal),
                    NomeLanche     = lancheResult.Nome
                });


                foreach (var item in ingredientesTotal.ToList())
                {
                    _pedidoIngredienteRepository.SavePedidoIngrediente(new PedidoIngrediente
                    {
                        IdIngrediente = item.IdComplemento,
                        IdPedido      = resultPedido.IdPedido
                    });
                }

                _unitOfWork.Commit();

                return(resultPedido);
            }
            catch (Exception e)
            {
                _unitOfWork.Rollback();
            }
            finally
            {
                Dispose();
            }

            return(new Pedido());
        }
Esempio n. 2
0
        public Lanche GetLancheById(long id)
        {
            var inflacao = Convert.ToDecimal(_parametroRepository.GetParametroById((long)ParametroEnum.Inflacao).Valor);

            var lanche = _lancheRepository.GetLancheById(id);

            lanche.LancheIngredientes = lanche.LancheIngredientes.Select(x => new LancheIngrediente
            {
                Ingrediente = new Ingrediente
                {
                    IdIngrediente      = x.Ingrediente.IdIngrediente,
                    Nome               = x.Ingrediente.Nome,
                    LancheIngredientes = x.Lanche.LancheIngredientes,
                    Valor              = (x.Ingrediente.Valor) + (x.Ingrediente.Valor * inflacao / 100),
                    PedidoIngredientes = x.Ingrediente.PedidoIngredientes
                },
                IdLanche            = x.IdLanche,
                IdIngrediente       = x.IdIngrediente,
                Lanche              = x.Lanche,
                IdLancheIngrediente = x.IdIngrediente
            }).ToList();

            return(lanche);
        }