public void Delete() { using (GroupsRepository repo = new GroupsRepository(DataContext)) { repo.Delete(_id); } }
public async Task <BaseResponse> Create([FromBody] GroupCreateRequest request) { var response = new BaseResponse(); if (request == null || !ModelState.IsValid) { HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest; response.Message = "Invalid input(s)."; return(response); } var group = new Group { Name = request.Name, Private = request.Private, Size = request.Size }; try { Group createdGroup = null; if (await _groupsRepository.Create(group)) { createdGroup = await _groupsRepository.GetByName(group.Name); } else { throw new Exception(); } if (createdGroup != null) { if (await _groupsRepository.AddUser(HttpContext.User.GetUserId(), createdGroup.Id)) { response.Message = "Group successfully created!"; response.Success = true; } } } catch (Exception ex) { try { await _groupsRepository.Delete(group); // If the User addition fails, we need to delete the group we created. } catch { Console.WriteLine(ex.Message); HttpContext.Response.StatusCode = StatusCodes.Status500InternalServerError; response.Message = "Failed to delete created group."; } Console.WriteLine(ex.Message); HttpContext.Response.StatusCode = StatusCodes.Status500InternalServerError; response.Message = "Failed to create group."; } return(response); }
public string Delete(int id, string userId) { if (_repo.Delete(id, userId)) { return("Deleted"); } throw new Exception("That Group doesn't exist"); }
internal string Delete(int id, string userId) { Group foundGroup = GetById(id); if (foundGroup.UserId != userId) { throw new Exception("You cant delete things that dont belong to you. :c "); } if (_repo.Delete(id, userId)) { return("AHHHH YEAHHHH. Deleted. c:"); } throw new Exception("Somethin' strange in the neighborhood."); }
public async Task <IActionResult> RemoveTaskGroup(int id) { TaskGroup group = await GroupsRepository.GetByID(id); if (group.UserTasks == null) { group.UserTasks = new List <UserTask>(); } while (group.UserTasks.Any()) { await TasksRepository.Delete((group.UserTasks.ToList())[0].Id); } await GroupsRepository.Update(group); await GroupsRepository.Delete(id); return(RedirectToAction("Index")); }
public IActionResult OnPost(int id) { g_Method.Delete(id); return(RedirectToPage("/Groups/ShowGroups")); }
public void Delete(int id) { GroupsRepository.Delete(id); }