public async Task <ActionResult> RemoveGroupTask(TravelGroupandUserTaskandItems model, int TaskId) { habiticatravelEntities HabiticaORM = new habiticatravelEntities(); CustomTask selectedTask = HabiticaORM.CustomTasks.Single(t => t.TaskId == TaskId && t.UserId == null); var selectedTaskItems = HabiticaORM.CustomTaskItems.Where(t => t.TaskId == TaskId).ToList(); if (selectedTaskItems.Count != 0) { foreach (var item in selectedTaskItems) { HabiticaORM.CustomTaskItems.Remove(item); } } HabiticaORM.CustomTasks.Remove(selectedTask); List <TravelGroupUser> GroupUsers = new List <TravelGroupUser>(); GroupUsers = HabiticaORM.TravelGroupUsers.Where(u => u.TravelGroupId == model.TravelGroupandUser.TravelGroup.TravelGroupId).ToList(); foreach (TravelGroupUser user in GroupUsers) { HabiticaUser MyHabUser = HabiticaORM.HabiticaUsers.Single(u => u.UserId == user.UserId); CustomTask selectedUserTask = HabiticaORM.CustomTasks.Single(t => t.TravelGroupId == model.TaskAndItems.CustomTask.TravelGroupId && t.UserId == user.UserId && t.TaskName == model.TaskAndItems.CustomTask.TaskName); var selectedUserTaskItems = HabiticaORM.CustomTaskItems.Where(t => t.TaskId == selectedUserTask.TaskId).ToList(); if (selectedUserTaskItems.Count != 0) { foreach (var item in selectedUserTaskItems) { var ItemConfirm = (JObject)JObject.FromObject(await HabiticaHTTP.DeleteChecklistItem(selectedUserTask, item, MyHabUser)); HabiticaORM.CustomTaskItems.Remove(item); } } var ItemConfirm2 = (JObject)JObject.FromObject(await HabiticaHTTP.DeleteATask(selectedUserTask, MyHabUser)); HabiticaORM.CustomTasks.Remove(selectedUserTask); } HabiticaORM.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public async Task <ActionResult> RemoveTask(int TaskId) { var HabiticaORM = new habiticatravelEntities(); string UserId = User.Identity.GetUserId(); HabiticaUser MyHabUser = HabiticaORM.HabiticaUsers.Single(u => u.UserId == UserId); var selectedTask = HabiticaORM.CustomTasks.Where(t => t.TaskId == TaskId).FirstOrDefault(); var selectedTaskItems = HabiticaORM.CustomTaskItems.Where(t => t.TaskId == TaskId).ToList(); if (selectedTaskItems.Count != 0) { foreach (var item in selectedTaskItems) { var ItemConfirm = (JObject)JObject.FromObject(await HabiticaHTTP.DeleteChecklistItem(selectedTask, item, MyHabUser)); HabiticaORM.CustomTaskItems.Remove(item); } } var ItemConfirm2 = (JObject)JObject.FromObject(await HabiticaHTTP.DeleteATask(selectedTask, MyHabUser)); HabiticaORM.CustomTasks.Remove(selectedTask); HabiticaORM.SaveChanges(); return(RedirectToAction("Index", "Home")); }