public static Zidium.Core.Api.JoinEventData ConvertToCore(JoinEventDto data) { if (data == null) { return(null); } return(new Zidium.Core.Api.JoinEventData() { EventId = data.EventId, ComponentId = data.ComponentId, JoinKey = data.JoinKey, Count = data.Count, Importance = ConvertToCore(data.Importance), JoinInterval = data.JoinInterval, Message = data.Message, Version = data.Version, StartDate = data.StartDate, TypeId = data.TypeId }); }
public async Task <IActionResult> JoinEvent(JoinEventDto joinEventDto) { IDatabaseContext context = _getDatabaseContext(); { Event @event = await context.Events .Include(e => e.EventParticipations) .FirstOrDefaultAsync(e => e.Id == joinEventDto.EventId); if (@event == null) { return(BadRequest(RequestStringMessages.EventNotFound)); } User currentUser = await HttpContext.GetCurrentUserAsync(context); if (@event.EventParticipations.Any(e => e.Participant == currentUser)) { return(BadRequest(RequestStringMessages.UserAlreadyPartOfEvent)); } if (@event.IsPrivate && (@event.Organizer != currentUser)) { return(BadRequest(RequestStringMessages.InvitationRequired)); } var eventParticipation = new EventParticipation { Event = @event, Participant = currentUser }; context.EventParticipations.Add(eventParticipation); await context.SaveChangesAsync(); _auditLogger.LogInformation("{0}(): Joined event {1}", nameof(JoinEvent), @event.Id); return(Ok()); } }