Exemple #1
0
        public IActionResult Post([FromBody] EventTypeDto posteEventType)
        {
            if (posteEventType == null)
            {
                ModelState.AddModelError("EventType", "Check all required fields");
                return(BadRequest(ModelState));
            }

            var newEventType = new EventType(posteEventType.Description);

            _eventTypeRepository.Add(newEventType);
            _eventTypeRepository.SaveChanges();

            return(CreatedAtRoute("GetEventType", new { id = newEventType.Id }, Mapper.Map <EventType, EventTypeDto>(newEventType)));
        }
Exemple #2
0
        public EventTypeController(IEventTypeRepository eventTypeRepository)
        {
            _eventTypeRepository = eventTypeRepository;

            // TODO Remove before publish
            // Use this block just to create a first fake event type (browser tests) (to run the unit tests it isn´t necessary)
            if (_eventTypeRepository.GetAll().Result.Count == 0)
            {
                var eventType = new EventType("Celebration");

                _eventTypeRepository.Add(eventType);
                _eventTypeRepository.SaveChanges();
            }
        }