コード例 #1
0
ファイル: EntriesController.cs プロジェクト: PJMPR/Westeros
        public async Task <IActionResult> Create(EntriesCreateModel entry, int uid)
        {
            if (HttpContext.Session.GetInt32("Id") == null)
            {
                return(RedirectToAction(nameof(UserProfileController.SignIn)));
            }

            if (true /*ModelState.IsValid*/)
            {
                entry.UserProfileId = (int)HttpContext.Session.GetInt32("Id");

                ICollection <EntryIngredient> ing = new List <EntryIngredient>();
                ICollection <EntryRecipe>     rec = new List <EntryRecipe>();

                var en = new Entry
                {
                    Date          = entry.Date,
                    UserProfileId = entry.UserProfileId,
                };

                _context.Add(en);
                _context.SaveChanges();


                foreach (var item in entry.EntryRecipes.Where(i => i.Recipe.IsNew == true))
                {
                    rec.Add(new EntryRecipe
                    {
                        RecipeId = item.Recipe.Id,
                        Entry    = en,
                        EntryId  = en.Id
                    });
                }

                _context.EntryRecipes.AddRange(rec);
                _context.SaveChanges();

                foreach (var item in entry.EntryIngredients.Where(i => i.IngredientQuantity > 0))
                {
                    ing.Add(new EntryIngredient
                    {
                        IngredientId       = item.Ingredient.Id,
                        IngredientQuantity = item.IngredientQuantity,
                        Entry   = en,
                        EntryId = en.Id
                    });
                }

                _context.EntryIngredients.AddRange(ing);
                _context.SaveChanges();


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

            return(View(entry));
        }
コード例 #2
0
 public void CreateUserData(USER_DATA data)
 {
     using (var context = new DietDbContext())
     {
         context.CREATEUSERDATA(data.HEIGHT, data.WEIGHT, data.USER_ID);
         context.SaveChanges();
     }
 }
コード例 #3
0
 public void CreateUserLog(int userId, string deviceInfo)
 {
     using (var ctx = new DietDbContext())
     {
         ctx.ADDUSERLOG(userId, deviceInfo);
         ctx.SaveChanges();
     }
 }
コード例 #4
0
 public void SetNewPassword(int userId, string password)
 {
     using (var ctx = new DietDbContext())
     {
         ctx.CHANGEPASSWORD(password, userId);
         ctx.SaveChanges();
     }
 }
コード例 #5
0
        /*public void AddDiet(DIET diet)
         * {
         *  using (var ctx = new DietDbContext())
         *  {
         *      ctx.DIETS.Add(diet);
         *      ctx.SaveChanges();
         *  }
         * }*/

        public void AddProductToDiet(int dietId, int productId, int quantity)
        {
            using (var ctx = new DietDbContext())
            {
                ctx.ADDPRODUCTODIET(productId, dietId, quantity);
                ctx.SaveChanges();
            }
        }
コード例 #6
0
 public void AddUserDietsEntry(USER_DIETS entry)
 {
     using (var ctx = new DietDbContext())
     {
         ctx.USER_DIETS.Add(entry);
         ctx.SaveChanges();
     }
 }
コード例 #7
0
 public void AddProductToDb(PRODUCT product)
 {
     using (var ctx = new DietDbContext())
     {
         ctx.CREATEPRODUCT(product.PRODUCT_DESCRIPTION, product.KCAL_100, product.PROTEIN_100, product.FAT_100,
                           product.CARBS_100);
         ctx.SaveChanges();
     }
 }
コード例 #8
0
 public void DeleteAllDietProductsEntries(int dietId)
 {
     using (var ctx = new DietDbContext())
     {
         var items = ctx.DIET_PRODUCTS.Where(x => x.DIET_ID == dietId).ToList();
         ctx.DIET_PRODUCTS.RemoveRange(items);
         ctx.SaveChanges();
     }
 }
コード例 #9
0
 public void UpdateDate(int dietId, DateTime date)
 {
     using (var ctx = new DietDbContext())
     {
         var item = ctx.DIETS.Where(x => x.DIET_ID == dietId).FirstOrDefault();
         item.ENTRY_DATE = date;
         ctx.SaveChanges();
     }
 }
コード例 #10
0
 public void DeletUserData(int id)
 {
     using (var context = new DietDbContext())
     {
         var itemToRemove = context.USER_DATA.FirstOrDefault(x => x.USER_DATA_ID == id);
         if (itemToRemove != null)
         {
             context.USER_DATA.Remove(itemToRemove);
         }
         context.SaveChanges();
     }
 }
コード例 #11
0
 public void DeleteDiet(int dietId)
 {
     using (var ctx = new DietDbContext())
     {
         var item = ctx.DIETS.FirstOrDefault(x => x.DIET_ID == dietId);
         if (item != null)
         {
             var userDiets = item.USER_DIETS;
             ctx.USER_DIETS.RemoveRange(userDiets);
             ctx.DIETS.Remove(item);
             ctx.SaveChanges();
         }
     }
 }