예제 #1
0
        public IActionResult Post([FromBody] EventDto postedEvent)
        {
            if (postedEvent == null)
            {
                ModelState.AddModelError("Event", "Check all required fields");
                return(BadRequest(ModelState));
            }

            if (postedEvent.TypeId == 0)
            {
                ModelState.AddModelError("EventType", "You must provide the TypeId");
                return(BadRequest(ModelState));
            }

            var eventType = _eventTypeRepository.GetOne(postedEvent.TypeId);

            if (eventType.IsCompleted && eventType.Result == null)
            {
                ModelState.AddModelError("EventType", "The Event Type provided does not exists");
                return(BadRequest(ModelState));
            }

            var newEvent = new Event(postedEvent.Description, postedEvent.Summary, postedEvent.Date, eventType.Result)
            {
                Price = postedEvent.Price, ImageLink = postedEvent.ImageLink
            };

            _eventRepository.Add(newEvent);
            _eventRepository.SaveChanges();

            return(CreatedAtRoute("GetEvent", new { id = newEvent.Id }, Mapper.Map <Event, EventDto>(newEvent)));
        }
예제 #2
0
        public IActionResult Get(int id)
        {
            var _eventType = _eventTypeRepository.GetOne(id).Result;

            if (_eventType == null)
            {
                return(NotFound());
            }

            return(new ObjectResult(Mapper.Map <EventType, EventTypeDto>(_eventType)));
        }
예제 #3
0
        public void EventTypeControllerPutTest()
        {
            // Arrange
            controller = new EventTypeController(_eventTypeRepository);
            var eventTypeDescription = "Celebration changed";
            var eventType = new EventTypeDto() { Id = 1, Description = eventTypeDescription };

            // Act
            var result = controller.Put(1, eventType);

            // Assert
            Assert.IsInstanceOfType(result, typeof(NoContentResult));
            Assert.AreEqual(eventTypeDescription, _eventTypeRepository.GetOne(1).Result.Description);
        }