public async Task <IActionResult> RemoveMembersInBadge([FromRoute] int badgeId, [FromRoute] int memberId) { var badge = await _context.BadgeMembers.FirstOrDefaultAsync(x => x.BadgeId == badgeId && x.MemberId == memberId); if (badge == null) { return(BadRequest("El miembro que esta intentando asignar ya tiene ese Badge")); } _context.Remove(badge); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Handle(DeleteBadgeCommand request, CancellationToken cancellationToken) { var badge = await _context.Badges.FirstOrDefaultAsync(x => x.Id == request.Id); if (badge == null) { return(new StatusCodeResult(404)); } if (!(await _context.Badges.AnyAsync(x => x.Id == request.Id && !x.Members.Any()))) { return(new StatusCodeResult(409)); } if (await badgesServices.RemoveAsync(badge.ImageName)) { _context.Remove(badge); await _context.SaveChangesAsync(); } return(new ObjectResult(request) { StatusCode = 200 }); }