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(); } }
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))); }
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); }