public async Task <ActionResult> Create(string description)
        {
            var execRes = new ExecutionResult();

            if (string.IsNullOrWhiteSpace(description))
            {
                execRes.AddError("Invalid description was given. Please try again.").PushTo(TempData);
                return(RedirectToAction(nameof(Index)));
            }

            var ppc = new PizzaPriceCategory {
                Description = description
            };
            await _context.PizzaPriceCategories.AddAsync(ppc);

            if (await _context.SaveChangesAsync() > 0)
            {
                execRes.AddSuccess("Price category was successfully added.");
            }
            else
            {
                execRes.AddError("Database error occured. Price category could not be added.");
            }

            execRes.PushTo(TempData);
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 2
0
        private void GenMockData()
        {
            var uId = new Guid("ec04ee08-f434-41d0-a208-15bd2dcb3389");
            var pId = Guid.NewGuid();
            var ppc = new PizzaPriceCategory {
                Description = "LOL", Id = 1
            };
            var user = new ApplicationUser {
                Id = uId.ToString(), Email = "*****@*****.**", UserName = "******"
            };

            _context.Users.Add(user);
            _context.Users.Add(new ApplicationUser {
                Id = Guid.NewGuid().ToString(), Email = "*****@*****.**", UserName = "******"
            });
            _context.PizzaPriceCategories.Add(ppc);
            _context.SaveChanges();
            _context.PizzaPriceInfo.Add(new PizzaPriceInfo {
                Id = 1, Price = 6.05m, PriceCategory = ppc, Size = 32
            });
            _context.Pizzas.Add(new Pizza {
                Id = pId, NameEn = "Havaian", PriceCategory = _context.PizzaPriceCategories.Single(c => c.Id == 1)
            });
            _context.SaveChangesAsync();
        }