public async Task RemovePlanFromGroupAsync(int groupId, int planId) { Group group = await GetAsync(groupId); GroupPlan findPlan = await Context.GroupPlans.FirstOrDefaultAsync(plan => plan.Plan.Id == planId); group.GroupPlans.Remove(findPlan); }
public async Task <bool> RemovePlanFromGroupAsync(int groupId, int planIdToRemove) { var group = await db.Groups.GetAsync(groupId); var plan = await db.Plans.Get(planIdToRemove); if (group == null || plan == null) { return(false); } await DeleteUserTasksOnRemovingPlanAsync(groupId, planIdToRemove); GroupPlan groupPlanToRemove = group.GroupPlans.Where(gp => gp.PlanId == planIdToRemove).FirstOrDefault(); bool removalSuccessful = group.GroupPlans.Remove(groupPlanToRemove); db.Save(); return(removalSuccessful); }
public async Task <bool> AddPlanToGroupAsync(int planId, int groupId) { Plan plan = await Context.Plans.FirstOrDefaultAsync(p => p.Id == planId); Group group = await Context.Groups.FirstOrDefaultAsync(g => g.Id == groupId); if (plan == null || group == null) { return(false); } GroupPlan groupPlan = new GroupPlan() { GroupId = groupId, PlanId = planId }; await Context.GroupPlans.AddAsync(groupPlan); return(true); }