Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,StreetAddress,City,State,Zip")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ID,OrderType,DriverOut,DriverIn")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(order));
        }
        public async Task <IActionResult> Create([Bind("ID,type,Price")] OrderItem orderItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(orderItem));
        }
        public async Task <IActionResult> Create([Bind("ID,Name,QuantityRemaining,PricePerUnit,Type")] InventoryItem inventoryItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(inventoryItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(inventoryItem));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Role,PhoneNumber,Salary")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(employee));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id_Produto,Nome,Preco,Tamanho,Descricao")] Produtos produtos)
        {
            if (ModelState.IsValid)
            {
                _context.Add(produtos);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(produtos));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Post(PizaaItem pizzaItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data"));
            }
            await _pizzaContext.PizaaItems.AddAsync(pizzaItem);

            await _pizzaContext.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("OrderIdPk,UsernameFk,OrderTotalCost,OrderDateTime,LocationFk")] OrderTable orderTable)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderTable);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LocationFk"] = new SelectList(_context.LocationTable, "LocationPk", "LocationPk", orderTable.LocationFk);
            ViewData["UsernameFk"] = new SelectList(_context.UserTable, "UsernamePk", "UsernamePk", orderTable.UsernameFk);
            return(View(orderTable));
        }
Exemplo n.º 9
0
        public async Task AddRange(List <PizzaOrder> pizzaOrders)
        {
            try
            {
                await context.AddRangeAsync(pizzaOrders);

                await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Create([Bind("ID,CustomerID,OrderType")] OrderAddViewModel orderVM)
        {
            if (ModelState.IsValid)
            {
                Order order = new Order();
                order.Customer   = _context.customers.FirstOrDefault(c => c.ID == orderVM.CustomerID);
                order.OrderType  = orderVM.OrderType;
                order.OrderItems = new List <OrderItem>();
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(orderVM));
        }
Exemplo n.º 11
0
        public async Task OrderPizza(string customer, List <int> pizzaIds)
        {
            var order = new Order
            {
                Customer  = customer,
                CreatedAt = DateTime.UtcNow.Date
            };

            _dbContext.Orders.Add(order);
            await _dbContext.SaveChangesAsync();

            var pizzas = await _dbContext.Pizzas.Where(x => pizzaIds.Contains(x.Id)).ToListAsync();

            _dbContext.PizzaOrders.AddRange(pizzas.Select(x => new PizzaOrder {
                OrderId = order.Id, PizzaId = x.Id
            }));
            await _dbContext.SaveChangesAsync();
        }
Exemplo n.º 12
0
        public async Task <IActionResult> AddEditPizza(AddEditPizzaModel newPizzaModel)
        {
            var newPizza = newPizzaModel.Pie;

            if (!ModelState.IsValid)
            {
                return(View(newPizzaModel));
            }

            var pizza = _pizzaContext.Pies.FirstOrDefault(a => a.Id == newPizza.Id) ?? new Pie();

            if (pizza == null)
            {
                pizza = new Pie();
            }
            pizza.Name             = newPizza.Name;
            pizza.ShortDescription = newPizza.ShortDescription ?? "";
            pizza.LongDescription  = newPizza.LongDescription ?? "";
            pizza.Price            = newPizza.Price;
            pizza.IsPieOfTheWeek   = newPizza.IsPieOfTheWeek;
            //pizza.ImageUrl = newPizza.ImageUrl ?? "";
            //pizza.ImageThumbnailUrl = newPizza.ImageThumbnailUrl ?? "";


            if (newPizzaModel.Image != null)
            {
                pizza.SetImage(newPizzaModel.Image);
            }
            else
            {
                if (Id != 0)
                {
                    var tempPizza = _pizzaContext.Pies.FirstOrDefault(a => a.Id == newPizza.Id);
                    pizza.Image            = tempPizza.Image;
                    pizza.ImageContentType = tempPizza.ImageContentType;
                }
            }

            _pizzaContext.Entry(pizza).State = pizza.Id == default(long) ? EntityState.Added : EntityState.Modified;
            await _pizzaContext.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 13
0
 public async Task <IActionResult> Save(int id, [Bind("OrderId,PizzaSize,PizzaQuantity,PizzaSizeList,Toppings,NumberOfToppings,ToppingsList,Subtotal,Tax,TotalPrice")] Order order)
 {
     if (ModelState.IsValid)
     {
         order.PizzaQuantity    = order.PizzaSizeList.Count;
         order.NumberOfToppings = order.ToppingsList.Count;
         order.PizzaSize        = JsonConvert.SerializeObject(order.PizzaSizeList);
         order.Toppings         = JsonConvert.SerializeObject(order.ToppingsList);
         order.TotalPrice       = Decimal.Round(CalculatePrice(order.PizzaSizeList, order), 2);
         if (id == 0)
         {
             _context.Add(order);
             await _context.SaveChangesAsync();
         }
         else
         {
             try
             {
                 order.OrderId = id;
                 _context.Update(order);
                 await _context.SaveChangesAsync();
             }
             catch (DbUpdateConcurrencyException)
             {
                 if (!OrderExists(order.OrderId))
                 {
                     return(NotFound());
                 }
                 else
                 {
                     throw;
                 }
             }
         }
         return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "Receipt", order) }));
     }
     return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "Create", order) }));
 }
Exemplo n.º 14
0
        public async Task <ActionResult <PizzaDto> > Post(PizzaDto pizzaDto)
        {
            var pizza = new Pizza()
            {
                Id            = pizzaDto.Id,
                Size          = pizzaDto.Size,
                Crust         = pizzaDto.Crust,
                Cheese        = pizzaDto.Cheese,
                Sauce         = pizzaDto.Sauce,
                PizzaToppings = pizzaDto.Toppings.Select(t => new PizzaTopping()
                {
                    PizzaId   = pizzaDto.Id,
                    ToppingId = t.Id
                }).ToList()
            };

            await context.AddAsync(pizza);

            await context.SaveChangesAsync();

            return(Ok());
        }