public IActionResult EditEvent([FromRoute] Guid trackId, [FromRoute] Guid eventId, [FromBody] EditEventRequest request) { var userId = User.GetUserId(); var customizations = _mapper.Map <CustomizationsDto>(request.Customizations); var eventDto = new EventToEditDto(eventId, customizations); var @event = _eventService.EditEvent(userId, eventDto); var result = _mapper.Map <EventModel>(@event); return(Ok(result)); }
public EventDto EditEvent(Guid userId, EventToEditDto eventDto) { var oldEvent = _eventRepository.TryGetById(eventDto.Id); var track = TryGetAccessToTrack(userId, oldEvent.TrackId); var oldCustomizations = Customizations.GetCustomizationTypes(oldEvent.Customization.GetDto()); var allowedCustomizations = track.AllowedCustomizations.Concat(oldCustomizations); CheckNotAllowedCustomizationsInDto(eventDto.CustomizationDto, allowedCustomizations, track.Id); var customizations = new Customizations(eventDto.CustomizationDto, allowedCustomizations); var editedEvent = new Event(eventDto.Id, oldEvent.CreatedAt, track.Id, customizations); var editResult = _eventRepository.TryUpdate(editedEvent); return(new EventDto(editResult)); }
public void TestEditEvent_ForInvalidCreatorId_ThrowsAccessDeny() { DomainException exception = null; var editedEvent = new EventToEditDto(_event); try { _eventService.EditEvent(_invalidCreatorId, editedEvent); } catch (DomainException e) { exception = e; } Assert.AreEqual(DomainExceptionType.TrackAccessDenied, exception.Type); }