Esempio n. 1
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();
            }
        }
Esempio n. 2
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)));
        }
Esempio n. 3
0
        public new ValidationResult Add(EventType eventType)
        {
            var validationResult = new ValidationResult();

            if (!eventType.IsValid())
            {
                validationResult.AddError(eventType.ValidationResult);
                return(validationResult);
            }

            var validator         = new EventTypeIsVerifiedForRegistration();
            var validationService = validator.Validate(eventType);

            if (!validationService.IsValid)
            {
                validationResult.AddError(eventType.ValidationResult);
                return(validationResult);
            }

            eventTypeRepository.Add(eventType);

            return(validationResult);
        }