Example #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Friend).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FriendExists(Friend.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Example #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var recipeId = RecipeView.Id;
            var recipe   = await _context.Recipes.SingleAsync(r => r.Id == recipeId);

            _context.Attach(recipe).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecipeExists(RecipeView.Id))
                {
                    return(NotFound());
                }
                throw;
            }

            return(RedirectToPage("./Index"));
        }
Example #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var meal = _context.Meals
                       .Include(m => m.Cookings)
                       .Include(m => m.Presences)
                       .Single(m => m.Id == MealMV.Id);

            meal.Date = MealMV.Date;
            var recipeIds = meal.Cookings.Select(c => c.RecipeId).ToArray();

            _context.AddRange(
                MealMV.SelectedRecipeIds
                .Where(recipeId => !recipeIds.Contains(recipeId))
                .Select(recipeId => new Cooking {
                MealId = meal.Id, RecipeId = recipeId
            })
                );
            _context.RemoveRange(meal.Cookings.Where(c => !MealMV.SelectedRecipeIds.Contains(c.RecipeId)));

            var friendIds = meal.Presences.Select(c => c.FriendId).ToArray();

            _context.AddRange(
                MealMV.SelectedFriendIds
                .Where(friendId => !friendIds.Contains(friendId))
                .Select(friendId => new Presence {
                MealId = meal.Id, FriendId = friendId
            })
                );
            _context.RemoveRange(meal.Presences.Where(p => !MealMV.SelectedFriendIds.Contains(p.FriendId)));

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MealExists(meal.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Example #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var meal = _mapper.Map <Meal>(MealView);

            _context.Update(meal);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var friend = _mapper.Map <Friend>(FriendMV);

            _context.Friends.Add(friend);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var recipe = _mapper.Map <Recipe>(RecipeModelView);

            _context.Recipes.Add(recipe);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Example #7
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Friend = await _context.Friends.FindAsync(id);

            if (Friend != null)
            {
                _context.Friends.Remove(Friend);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }