Exemplo n.º 1
0
        public async Task <ActionResult <EventViewDto> > CreateEvent([FromBody] EventInputDto eventInputDto)
        {
            if (eventInputDto == null)
            {
                return(BadRequest());
            }

            //model state validation is not required due to the [ApiController] attribute automatically returning UnprocessableEntity (see startup.cs)
            //when model binding fails

            //fetch the user id from the JWT via HttpContext. Then get the user from the repository. This is to ensure that an authorized user
            //is calling the API with a valid user id
            var user = await _userRepository.GetUserAsync(User.GetUserId());

            if (user == null)
            {
                return(BadRequest(new { Error = "The user was not found in the system. Please try again with an authorized and valid user." }));
            }

            var eventToAdd = _mapper.Map <Event>(eventInputDto); //map EventInputDto to Event

            eventToAdd.UserId = user.Id;                         //set the user id as otherwise navigation property will be null
            _eventRepository.AddEvent(eventToAdd);

            if (!await _eventRepository.SaveChangesAsync())
            {
                throw new Exception($"Error saving Event {eventToAdd.Id} to the database");
            }

            var eventToReturn = _mapper.Map <EventViewDto>(eventToAdd);

            return(CreatedAtRoute("GetEvent", new { id = eventToAdd.Id }, eventToReturn));
        }
Exemplo n.º 2
0
        public async Task Add_InvalidEvent_Returns_BadRequest()
        {
            //Arrange
            EventInputDto x = null;

            //Act
            var result = await eventsController.CreateEvent(x);

            //Assert
            Assert.IsType <BadRequestResult>(result.Result);
        }
Exemplo n.º 3
0
        public EventInputDto ConfigureEventBeforeEdit(int eventId)
        {
            var @event     = _eventService.Get(eventId);
            var layout     = _layoutService.Get(@event.LayoutId);
            var venue      = _venueService.Get(layout.VenueId);
            var eventAreas = _eventAreaService.List(eventArea => eventArea.EventId == eventId).ToList();

            var eventInput = new EventInputDto
            {
                VenueDescriptionValue  = venue.Description,
                LayoutDescriptionValue = layout.Description,
                Event      = _mapper.Map <EventDto>(@event),
                EventAreas = eventAreas,
            };

            return(eventInput);
        }
Exemplo n.º 4
0
        public EventDto EditEvent(EventInputDto input)
        {
            var result = _eventService.Save(input.Event);

            var eventAreas = _eventAreaService.List(eventArea => eventArea.EventId == result.Id);

            foreach (var eventArea in eventAreas)
            {
                var eventAreaByDescription = input.EventAreas.FirstOrDefault(x => x.Description == eventArea.Description) ??
                                             throw new ArgumentNullException("Can not find Event Area by Description");

                eventArea.Price = eventAreaByDescription.Price;

                _eventAreaService.Save(eventArea);
            }

            return(result);
        }
Exemplo n.º 5
0
        public EventInputDto ConfigureEventBeforeCreation(int layoutId)
        {
            var venueId           = _layoutService.Get(layoutId).VenueId;
            var venueDescription  = _venueService.Get(venueId).Description;
            var layoutDescription = _layoutService.Get(layoutId).Description;
            var areas             = _areaService.List(area => area.LayoutId == layoutId).ToList();
            var eventAreas        = _mapper.Map <List <EventAreaDto> >(areas);

            var @event = new EventDto
            {
                LayoutId = layoutId,
                Date     = DateTime.Now.AddDays(1),
            };

            var newEventInput = new EventInputDto
            {
                VenueDescriptionValue  = venueDescription,
                LayoutDescriptionValue = layoutDescription,
                Event      = @event,
                EventAreas = eventAreas,
            };

            return(newEventInput);
        }
Exemplo n.º 6
0
 public EventDto CreateEvent(EventInputDto input)
 {
     return(EditEvent(input));
 }
Exemplo n.º 7
0
 public EventDto EditEvent(EventInputDto input)
 {
     return(_eventManageService.EditEvent(input));
 }
Exemplo n.º 8
0
 public EventDto CreateEvent(EventInputDto input)
 {
     return(_eventManageService.CreateEvent(input));
 }