コード例 #1
0
ファイル: RecipeController.cs プロジェクト: PJMPR/Westeros
 public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Cuisine,Desription,PrepTime,Difficulty")] Data.Recipe recipe)
 {
     if (HttpContext.Session.GetInt32("Id") == null)
     {
         return(RedirectToAction(nameof(UserProfileController.SignIn)));
     }
     else
     {
         if (id != recipe.Id)
         {
             return(NotFound());
         }
         if (ModelState.IsValid)
         {
             try
             {
                 _context.Update(recipe);
                 await _context.SaveChangesAsync();
             }
             catch (DbUpdateConcurrencyException)
             {
                 if (!RecipeExists(recipe.Id))
                 {
                     return(NotFound());
                 }
                 throw;
             }
             return(RedirectToAction(nameof(IndexAsync)));
         }
         return(View(recipe));
     }
 }
コード例 #2
0
        public Data.Recipe AddRecipe(API.ANet.Recipe recipe)
        {
            if (this._recipes.Where(r => r.Id != null && r.Id == int.Parse(recipe.recipe_id)).Count() == 0)
            {
                Data.Recipe newrecipe = new Data.Recipe(recipe, false, false, _session_id);
                this._recipes.Add(newrecipe);
                this.SaveRecipe(newrecipe);

                return(newrecipe);
            }
            return(null);
        }
コード例 #3
0
ファイル: RecipeController.cs プロジェクト: PJMPR/Westeros
        public async Task <IActionResult> Create([Bind("Id,Name,Cuisine,Desription,PrepTime,Difficulty")] Data.Recipe recipe)
        {
            if (HttpContext.Session.GetInt32("Id") == null)
            {
                return(RedirectToAction(nameof(UserProfileController.SignIn)));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(recipe);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(IndexAsync)));
                }
                return(View(recipe));
            }
        }