public string GenerateOrder(Order order, List <int> BeerIds) { foreach (var id in BeerIds) { order.BeerIds.Add(new ShopListItem() { ItemId = id }); } db.Orders.Add(order); db.SaveChanges(); return("Thanks" + order.User); }
public static void Initialize(BeerStoreContext context) { bool isBeers = context.Beers.Any(); bool isUsers = context.Users.Any(); bool anyChanges = false; if (!isBeers) { GenerateBeers(context); anyChanges = true; } if (!isUsers) { GenerateUsers(context); anyChanges = true; } if (anyChanges) { context.SaveChanges(); } }
public async Task <IActionResult> Register(User user, IFormFile avatar) { string localPath = "/img/user/"; if (avatar != null) { localPath += avatar.FileName; string globalPath = env.WebRootPath + localPath; using (FileStream fs = new FileStream(globalPath, FileMode.Create)) { await avatar.CopyToAsync(fs); } } else { localPath += "user.png"; } user.AvaUrl = localPath; db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Users")); }
public IActionResult Create(Beer beer) { db.Beers.Add(beer); db.SaveChanges(); return(RedirectToActionPermanent("Beers")); }