public override void RemoveBadge(RemoveBadgeRequestDto request) { try { base.RemoveBadge(request); } catch (Exception ex) { _log.LogError(ex.Message, ex); throw; } }
public override void RemoveBadge(RemoveBadgeRequestDto request) { base.RemoveBadge(request); //Log event var system = _context.Systems .FirstOrDefault(x => x.ExternalId == request.SystemExternalId); var ev = new Event { System = system }; ev.SetName($"Badge '{request.BadgeName}' was removed."); ev.SetTimestamp(DateTime.UtcNow); ev.SetType(EventType.BadgeRemoved); _logger.LogEvent($"Badge '{request.BadgeName}' was removed.", ev); }
public void RemoveBadge(RemoveBadgeRequestDto request) { var system = _context.Systems .Include(x => x.Badges) .Include(x => x.Pages) .Include(x => x.Categories) .Include(x => x.Users) .FirstOrDefault(x => x.ExternalId == request.SystemExternalId); var existingBadge = system.Badges .FirstOrDefault(x => x.Name == request.BadgeName); var pages = system.Pages .Where(x => x.BadgeId == existingBadge.Id) .ToList(); pages.ForEach(x => x.BadgeId = null); var categories = system.Categories .Where(x => x.BadgeId == existingBadge.Id) .ToList(); categories.ForEach(x => x.BadgeId = null); var users = system.Users .Where(x => x.EarnedBadges.Select(y => y.BadgeId).Contains(existingBadge.Id)) .ToList(); foreach (var user in users) { var badges = user.EarnedBadges .Where(x => x.BadgeId == existingBadge.Id) .ToList(); badges.ForEach(x => user.EarnedBadges.Remove(x)); } system.Badges .Remove(existingBadge); _context.SaveChanges(); }
public override void RemoveBadge(RemoveBadgeRequestDto request) { var system = _context.Systems .AsNoTracking() .FirstOrDefault(x => x.ExternalId == request.SystemExternalId); if (system == null) { throw new SystemNotFoundException(request.SystemExternalId, $"External Id '{request.SystemExternalId}' is not valid.", "RemoveBadgeRequestDto.SystemExternalId"); } var existingBadge = system.Badges .Where(x => x.SystemId == system.Id) .FirstOrDefault(x => x.Name == request.BadgeName); if (existingBadge == null) { throw new EntityNotFoundException("Badge", $"Badge '{request.BadgeName}' was not found.", "RemoveBadgeRequestDto.BadgeId"); } base.RemoveBadge(request); }
public virtual void RemoveBadge(RemoveBadgeRequestDto request) { _inner.RemoveBadge(request); }