Exemple #1
0
 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);
 }
Exemple #2
0
        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();
            }
        }
Exemple #3
0
        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"));
        }
Exemple #4
0
 public IActionResult Create(Beer beer)
 {
     db.Beers.Add(beer);
     db.SaveChanges();
     return(RedirectToActionPermanent("Beers"));
 }