public Task Add(Pizza newPizza) { return(Task.Run(() => { _repository.Add(newPizza); })); }
public async Task <IActionResult> Create([Bind("Id,Name,Price,Description,ImageUrl,IsPizzaOfTheWeek")] Pizzas pizza) { if (ModelState.IsValid) { _pizzaRepo.Add(pizza); await _pizzaRepo.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(pizza)); }
public async Task <IActionResult> Create([Bind("Id,Name,Price,Description,ImageUrl,IsPizzaOfTheWeek,CategoriesId")] Pizzas pizzas) { if (ModelState.IsValid) { _pizzaRepo.Add(pizzas); await _pizzaRepo.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["CategoriesId"] = new SelectList(_categoryRepo.GetAll(), "Id", "Name", pizzas.CategoriesId); return(View(pizzas)); }
public IActionResult Create(CreatePizzaViewModel model) { if (ModelState.IsValid) { var pizza = new Pizza(); pizza.Name = model.Name; pizza.PizzaTypeId = model.PizzaTypeId; pizza.Size = model.Size; pizza.Price = model.Price; pizzas.Add(pizza); return(RedirectToAction("Index")); } return(View("Create")); }
public IActionResult Create(CreatePizzaViewModel model) { if (ModelState.IsValid) { Pizza pizza = new Pizza(); pizza.Name = model.Name; pizza.PizzaTypeID = model.PizzaTypeID; pizza.Price = model.Price; pizza.Size = model.Size; pizzas.Add(pizza); int count = pizzas.GetAll().Count(); return(RedirectToAction("index")); } return(View()); }
public ResultEntity <Pizza> Add(Pizza pizza) { try { var _pizza = _repository.GetBySabor(pizza.Sabor); if (_pizza != null) { return(ResultEntity <Pizza> .Fail(pizza, $"Já existe uma pizza com o sabor - {pizza.Sabor}")); } _repository.Add(pizza); return(ResultEntity <Pizza> .Success(pizza)); } catch (Exception e) { return(ResultEntity <Pizza> .Fail(pizza, $"Ocorreu algum erro na criação da pizza - {e.Message}")); } }
public PizzaMutation(IPizzaRepository pizzaRepository) { Name = "PizzaMutations"; Field <PizzaType>( "createPizza", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <PizzaInputType> > { Name = "pizza" } ), resolve: context => { dynamic pizzaInput = context.Arguments["pizza"]; string name = pizzaInput["name"]; List <object> toppingKeys = pizzaInput["toppings"]; var pizza = new Pizza() { Name = name, PizzaToppings = toppingKeys.Select(tk => new PizzaTopping() { ToppingId = (int)tk }).ToList() }; pizzaRepository.Add(pizza); return(this.loadPizza(pizza.Id, context, pizzaRepository)); }); Field <PizzaType>( "updatePizza", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <PizzaInputType> > { Name = "pizza" } ), resolve: context => { dynamic pizzaInput = context.Arguments["pizza"]; string name = pizzaInput["name"]; int id = pizzaInput["id"]; List <object> toppingKeys = pizzaInput["toppings"]; var pizza = new Pizza() { Id = id, Name = name, PizzaToppings = toppingKeys.Select(tk => new PizzaTopping() { PizzaId = id, ToppingId = (int)tk }).ToList() }; pizzaRepository.Update(pizza); return(this.loadPizza(pizza.Id, context, pizzaRepository)); }); Field <StringGraphType>( "deletePizza", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "id" } ), resolve: context => { int id = (int)context.Arguments["id"]; pizzaRepository.Delete(id); return("OK"); }); }
public void Create(string ingids, PizzaItem item) { db.Add(ingids, item); }
public void InsertPizza(Pizza pizza) { _pizzaRepository.Add(pizza); }