Example #1
0
        public async Task <IActionResult> Delete([FromBody] ViewUser model, [FromRoute] int groupId)
        {
            // TODO think about check if group exist and add error about it
            // TODO use UserService
            var dto = await _groupMemberService.GetAllByGroupAndUserId(model.Id, groupId);

            if (!dto.Succeeded)
            {
                return(BadRequest(dto.Errors));
            }

            var result = await _groupMemberService.Delete(dto.Result.Id);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }

            var dtos = await _groupMemberService.GetAllByGroupId(groupId);

            if (!dtos.Succeeded)
            {
                return(BadRequest(dtos.Errors));
            }

            // if number of GroupMember in Group is equal 0
            // Group must be deleted
            if (dtos.Result.Any())
            {
                return(NoContent());
            }

            result = await _groupMemberService.Delete(dto.Result.Id);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors));
            }

            return(NoContent());
        }
 public ActionResult DeleteGroupMember(int groupMemberId, int userTypeId)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             throw new Exception(ModelState.ToString());
         }
         _groupMemberService.Delete(groupMemberId, userTypeId);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Example #3
0
 public IActionResult Delete(int id)
 {
     try
     {
         var originalGroupMember = _groupMemberService.Find(id);
         if (originalGroupMember == null)
         {
             return(NotFound());
         }
         _groupMemberService.Delete(originalGroupMember);
         return(Ok());
     }
     catch
     {
         return(StatusCode(500));
     }
 }