public PizzaViewModel GetById(int id) { var pizza = _pizzaRepository.Get(id); var pizzaView = new PizzaViewModel(pizza); return(pizzaView); }
public Task <Pizza> Get(int id) { return(Task.Run(() => { return _repository.Get(id); })); }
public ActionResult <Pizza> Get(int id) { try { return(Ok(_pizzaRepository.Get(id))); } catch (Exception e) { return(NotFound(e.Message)); } }
public PizzaViewModel GetById(int id) { try { var pizza = _pizzaRepository.Get(id); var pizzaView = new PizzaViewModel(pizza); return(pizzaView); } catch (Exception) { return(null); } }
public async Task <IEnumerable <RequestHistoryCollection> > GetHistoryByIdCustomer(int idCustomer) { var requestHistory = new List <RequestHistoryCollection>(); var requests = await Get(x => x.IdCustomer == idCustomer); if (requests.Count() == 0) { return(requestHistory); } var query = (from r in requests.AsQueryable() join c in _db.Customers.AsQueryable() on r.IdCustomer equals c.Id into jrc from jrcx in jrc.DefaultIfEmpty() where jrcx.Id == idCustomer select new { r, c = jrcx }) .ToList() .OrderBy(o => o.r.Id) .ToList(); query.ForEach(e => { e.r.SetAddress(e.c.Address); }); var pizzas = _pizzaRepository.Get(x => x.Active).Result; query .Select(s => s.r) .ToList() .ForEach(e => { var requestHistoryPizzas = new List <RequestHistoryPizzaCollection>(); var requestPizzas = _requestPizzaRepository.Get(w => w.IdRequest == e.Id).Result.OrderBy(o => o.Id).ToList(); requestPizzas.ForEach(e => { var firstHalfPizza = pizzas.FirstOrDefault(w => w.Id == e.IdPizzaFirstHalf); var secondHalfPizza = pizzas.FirstOrDefault(w => w.Id == e.IdPizzaSecondHalf); var requestHistoryPizza = new RequestHistoryPizzaCollection( new RequestHistoryPizzaInfoCollection(firstHalfPizza.Name, firstHalfPizza.Price), new RequestHistoryPizzaInfoCollection(secondHalfPizza.Name, secondHalfPizza.Price), e.Quantity, e.Total); requestHistoryPizzas.Add(requestHistoryPizza); }); requestHistory.Add(new RequestHistoryCollection(e.Uid, e.CreatedAt, requestHistoryPizzas, e.Quantity, e.Total)); }); return(requestHistory); }
public async Task <ICommandQuery> Handle(PizzaGetQuery query, CancellationToken cancellationToken) { var pizzas = await _repo.Get(query.Get()); if (pizzas.ToList().Count == 0) { query.AddError(2010); } else { query.SetData(pizzas); } return(query); }
public async Task <ICommandQuery> Handle(PizzaGetQuery query, CancellationToken cancellationToken) { var collections = await _repo.Get(query.Get()); if (collections.ToList().Count == 0) { query.AddError(2010); } else { var pizzas = _mapper.Map <IEnumerable <Pizza> >(collections); query.SetData(pizzas); } return(query); }
public IActionResult Details(int id) { var pica = pizzas.Get(id); return(View(pica)); }
public Pizza GetPizza(int?id) { var result = _pizzaRepository.Get(id); return(result); }
public ActionResult <Pedido> Cadastrar(Pedido model) { try { if (model.Itens == null || model.Itens.Count == 0 || model.Itens.Count > 10) { return(BadRequest("Um pedido pode ter no mínimo uma pizza e no máximo 10.")); } if (model.CodCliente != 0) { var endereco = _clienteRepository.Get(model.CodCliente); if (endereco != null) { model.Bairro_Entrega = endereco.Bairro; model.Cidade_Entrega = endereco.Cidade; model.Complemento_Entrega = endereco.Complemento; model.Estado_Entrega = endereco.Estado; model.Logradouro_Entrega = endereco.Logradouro; model.Numero_Entrega = endereco.Numero; model.NomeCliente = endereco.Nome; model.Email = endereco.Email; model.Telefone = endereco.Telefone; } else { return(BadRequest("O cliente informado, não foi encontrado;")); } } #region calcula Preço decimal valorTotal = 0; foreach (var item in model.Itens) { if (item.Pizza == null || item.Pizza.Count == 0) { return(BadRequest("Nenhuma pizza foi adicionada!")); } if (item.Pizza.Count > 2) { return(BadRequest("Cada pizza deve ter no mínimo dois sabores!")); } foreach (var subItem in item.Pizza) { var pizza = _pizzaRepository.Get(subItem.CodPizza); subItem.Nome = pizza.Nome; if (item.Pizza.Count == 1) { valorTotal += pizza.Preco; subItem.Preco = pizza.Preco; } else { var valorItem = (pizza.Preco / 2); valorTotal += valorItem; subItem.Preco = valorItem; } } } model.PrecoTotal = valorTotal; #endregion model.CodPedido = _pedidoRepository.Add(model).CodPedido; foreach (var item in model.Itens) { item.CodPedido = model.CodPedido; item.CodPedidoItem = _pedidoItemRepository.Add(item).CodPedidoItem; foreach (var subItem in item.Pizza) { subItem.CodPedidoItem = item.CodPedidoItem; subItem.CodSubItem = _subItemRepository.Add(subItem).CodSubItem; } } return(Ok(model)); } catch (Exception e) { return(BadRequest()); } }
public IEnumerable <Pizza> Get() { return(_repository.Get()); }