コード例 #1
0
 public void Delete()
 {
     using (GroupsRepository repo = new GroupsRepository(DataContext))
     {
         repo.Delete(_id);
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
 public string Delete(int id, string userId)
 {
     if (_repo.Delete(id, userId))
     {
         return("Deleted");
     }
     throw new Exception("That Group doesn't exist");
 }
コード例 #4
0
        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.");
        }
コード例 #5
0
        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"));
        }
コード例 #6
0
ファイル: Delete.cshtml.cs プロジェクト: ramsalo1981/Store1
 public IActionResult OnPost(int id)
 {
     g_Method.Delete(id);
     return(RedirectToPage("/Groups/ShowGroups"));
 }
コード例 #7
0
 public void Delete(int id)
 {
     GroupsRepository.Delete(id);
 }