Пример #1
0
        public async Task <IActionResult> Create([Bind("Id,PizzeriaId,SpeciesId,AnimatronicName,AnimatronicInfo")] Animatronic animatronic)
        {
            bool duplicate = await _context.Animatronic.AnyAsync(a => a.AnimatronicName == animatronic.AnimatronicName);

            if (duplicate)
            {
                ModelState.AddModelError("AnimatronicName", "This animatronic already exists");
            }
            bool letCheck = animatronic.AnimatronicName.Any(x => char.IsLetter(x));

            if (!letCheck)
            {
                ModelState.AddModelError("AnimatronicName", "Animatronic name must have at least 1 letter in it!");
            }

            if (ModelState.IsValid)
            {
                _context.Add(animatronic);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PizzeriaId"] = new SelectList(_context.Pizzeria, "Id", "PizzeriaName", animatronic.PizzeriaId);
            ViewData["SpeciesId"]  = new SelectList(_context.Species, "Id", "SpeciesName", animatronic.SpeciesId);
            return(View(animatronic));
        }
Пример #2
0
        public async Task <IActionResult> Create(int mealId, int pizzeriaId, [Bind("Id,PizzeriaId,MealId")] PizzeriaMeal pizzeriaMeal)
        {
            //if (ModelState.IsValid)
            //{
            //    _context.Add(pizzeriaMeal);
            //    await _context.SaveChangesAsync();
            //    return RedirectToAction(nameof(Index));
            //}
            //ViewData["MealId"] = new SelectList(_context.Meal, "Id", "MealName", pizzeriaMeal.MealId);
            //ViewData["PizzeriaId"] = new SelectList(_context.Pizzeria, "Id", "Address", pizzeriaMeal.PizzeriaId);
            bool check = await _context.PizzeriaMeal.AnyAsync(p => p.MealId == mealId && p.PizzeriaId == pizzeriaId);

            if (check)
            {
                ViewBag.ErrorMessage = "Error! This transfer already exists!";
                ModelState.AddModelError("MealId", "Error!");
            }
            if (ModelState.IsValid)
            {
                _context.Add(pizzeriaMeal);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "PizzeriaMeals", new { id = pizzeriaId }));
            }
            ViewData["PizzeriaId"] = new SelectList(_context.Pizzeria, "Id", "PizzeriaName", pizzeriaMeal.PizzeriaId);
            ViewData["MealId"]     = new SelectList(_context.Meal, "Id", "MealName", pizzeriaMeal.MealId);
            return(View(pizzeriaMeal));
        }
        public async Task <IActionResult> Create([Bind("Id,EventId,UserId,OrderDate")] Orders orders)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orders);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "UserName", orders.UserId);
            return(View(orders));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("Id,MealId,OrderId,MealCount")] MealOrder mealOrder)
        {
            if (ModelState.IsValid)
            {
                _context.Add(mealOrder);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MealId"]  = new SelectList(_context.Meal, "Id", "MealName", mealOrder.MealId);
            ViewData["OrderId"] = new SelectList(_context.Orders, "Id", "Id", mealOrder.OrderId);
            return(View(mealOrder));
        }
        public async Task <IActionResult> Create([Bind("Id,UserId,PizzeriaId,ReviewDate,ReviewText")] Review review)
        {
            if (ModelState.IsValid)
            {
                review.ReviewDate = DateTime.Now;
                _context.Add(review);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PizzeriaId"] = new SelectList(_context.Pizzeria, "Id", "PizzeriaName", review.PizzeriaId);
            ViewData["UserId"]     = new SelectList(_context.Users, "Id", "UserName", review.UserId);
            return(View(review));
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("Id,CategoryName")] Category category)
        {
            bool duplicate = await _context.Category.AnyAsync(c => c.CategoryName == category.CategoryName);

            if (duplicate)
            {
                ModelState.AddModelError("CategoryName", "This category already exists");
            }
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("Id,SpeciesName")] Species species)
        {
            bool duplicate = await _context.Species.AnyAsync(s => s.SpeciesName == species.SpeciesName);

            if (duplicate)
            {
                ModelState.AddModelError("SpeciesName", "This species already exists");
            }
            if (ModelState.IsValid)
            {
                _context.Add(species);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(species));
        }
        public async Task <IActionResult> Create([Bind("Id,UserName")] Users users)
        {
            bool duplicate = await _context.Users.AnyAsync(u => u.UserName == users.UserName);

            if (duplicate)
            {
                ModelState.AddModelError("UserName", "This user already exists");
            }
            if (ModelState.IsValid)
            {
                _context.Add(users);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(users));
        }
        public async Task <IActionResult> Create([Bind("Id,CategoryId,MealName,MealInfo,MealPrice")] Meal meal)
        {
            bool duplicate = await _context.Meal.AnyAsync(m => m.MealName == meal.MealName);

            if (duplicate)
            {
                ModelState.AddModelError("MealName", "This meal already exists");
            }
            if (ModelState.IsValid)
            {
                _context.Add(meal);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "CategoryName", meal.CategoryId);
            return(View(meal));
        }
Пример #10
0
        public async Task <IActionResult> Create([Bind("Id,PizzeriaName,Address,PizzeriaInfo")] Pizzeria pizzeria)
        {
            bool duplicate = await _context.Pizzeria.AnyAsync(p => p.PizzeriaName == pizzeria.PizzeriaName);

            if (duplicate)
            {
                ModelState.AddModelError("PizzeriaName", "This pizzeria already exists");
            }
            string temp = pizzeria.Address.ToString().ToLower();
            var    dub  = _context.Pizzeria.Where(p => p.Id != pizzeria.Id).Include(p => p.Animatronic).ToList();

            foreach (var obj in dub)
            {
                string temp1 = obj.Address.ToString().ToLower();
                if (temp1 == temp)
                {
                    ModelState.AddModelError("Address", "The pizzeria with this address already exists");
                    break;
                }
            }
            bool letCheck = pizzeria.PizzeriaName.Any(x => char.IsLetter(x));

            if (!letCheck)
            {
                ModelState.AddModelError("PizzeriaName", "Pizzeria name must have at least 1 letter in it!");
            }

            if (ModelState.IsValid)
            {
                _context.Add(pizzeria);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pizzeria));
        }
        public async Task <IActionResult> Create([Bind("Id,EventName,EventInfo,EventPrice")] Event Event)
        {
            bool duplicate = await _context.Event.AnyAsync(e => e.EventName == Event.EventName);

            if (duplicate)
            {
                ModelState.AddModelError("EventName", "This Event already exists");
            }
            bool letCheck = Event.EventName.Any(x => char.IsLetter(x));

            if (!letCheck)
            {
                ModelState.AddModelError("EventName", "Event name must have at least 1 letter in it!");
            }

            if (ModelState.IsValid)
            {
                _context.Add(Event);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(Event));
        }