Exemplo n.º 1
0
 public Task Add(Pizza newPizza)
 {
     return(Task.Run(() =>
     {
         _repository.Add(newPizza);
     }));
 }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 4
0
 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"));
 }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
        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");
            });
        }
Exemplo n.º 8
0
 public void Create(string ingids, PizzaItem item)
 {
     db.Add(ingids, item);
 }
Exemplo n.º 9
0
 public void InsertPizza(Pizza pizza)
 {
     _pizzaRepository.Add(pizza);
 }