public IActionResult UpdateEvent(int id, [FromBody] EventFormDto eventFormDto)
        {
            if (!ModelState.IsValid)
            {
                var response = new ServerResponse <ModelStateDictionary>();
                response.Data = ModelState;
                return(BadRequest(response));
            }
            else
            {
                var response = new ServerResponse <Event>();
                var evt      = _eventService.GetEvent(id);

                if (evt is null)
                {
                    response.Message = "Event not found";
                    return(NotFound(response));
                }

                var evtUpdated = _mapper.Map(eventFormDto, evt);
                _eventService.UpdateEvent(evtUpdated);

                response.Data    = evtUpdated;
                response.Message = "Event successfully updated !";
                return(Ok(response));
            }
        }
Example #2
0
        public void EditEvent(EventFormDto eventFormDto)
        {
            var @event = _mappingInfrastructure.MapEventFormDtoToEvent(eventFormDto);

            @event.UserId = _authInfrastructure.GetCurrentUserId();
            _eventsRepository.Edit(@event);
            MovePhotosFromTempToDest(eventFormDto.PhotoNames);
        }
Example #3
0
        public int InsertEventAndReturnEventId(EventFormDto eventFormDto)
        {
            var @event = _mappingInfrastructure.MapEventFormDtoToEvent(eventFormDto);

            @event.UserId = _authInfrastructure.GetCurrentUserId();

            int eventId = _eventsRepository.InsertAndReturnId(@event);

            MovePhotosFromTempToDest(eventFormDto.PhotoNames);

            return(eventId);
        }
Example #4
0
        public ActionResult CreateEvent([Bind(Prefix = "EventFormDto")] EventFormDto eventFormDto)
        {
            if (!ModelState.IsValid)
            {
                var eventFormVewModel = _eventService.GetEventFormViewModel();
                eventFormVewModel.EventFormDto = eventFormDto;
            }

            int eventId = _eventService.InsertEventAndReturnEventId(eventFormDto);

            _photoService.InsertPhotos(eventId, eventFormDto.PhotoNames);

            return(RedirectToAction("ShowEvents"));
        }
Example #5
0
        public ActionResult EditEvent([Bind(Prefix = "EventFormDto")] EventFormDto eventFormDto)
        {
            if (!ModelState.IsValid)
            {
                var eventFormViewModel = _eventService.GetEventFormViewModel();
                eventFormViewModel.EventFormDto = eventFormDto;

                return(View(eventFormViewModel));
            }

            _eventService.EditEvent(eventFormDto);
            _photoService.EditPhotos(eventFormDto.Id, eventFormDto.PhotoNames);

            return(RedirectToAction("ShowEvents"));
        }
        public IActionResult CreateEvent([FromBody] EventFormDto eventFormDto)
        {
            if (!ModelState.IsValid)
            {
                var response = new ServerResponse <ModelStateDictionary>();
                response.Data = ModelState;
                return(BadRequest(response));
            }
            else
            {
                var evt = _mapper.Map <EventFormDto, Event>(eventFormDto);
                _eventService.CreateEvent(evt);

                var response = new ServerResponse <Event>();
                response.Data    = evt;
                response.Message = "Event successfully created !";
                return(CreatedAtAction(nameof(GetEvent), new { id = evt.Id }, response));
            }
        }
        public Event MapEventFormDtoToEvent(EventFormDto eventFormDto)
        {
            var @event = _mapper.Map <EventFormDto, Event>(eventFormDto);

            return(@event);
        }