public void CreateEvent_Returns_Event_With_Uri()
        {
            //Arrange
            var newEvent = new Event
            {
                Title = "New Event"
            };
            var eventService = A.Fake<IEventsService>();
            A.CallTo(() => eventService.AddEvent(A<Event>.Ignored)).Invokes(x =>
                {
                    var evt = x.GetArgument<Event>("newEvent");
                    evt.ID = 1;
                });
            var controller = new EventsController(eventService);
            WebApiTestHelper.SetupController(controller, "events/createEvent");

            //Act
            var response = controller.CreateEvent(newEvent);
            var eventContent = response.Content.ReadAsAsync<Event>().Result;

            //Assert
            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.Equal(newEvent, eventContent);
            Assert.True(response.Headers.Location.AbsoluteUri.EndsWith("eventID=" + eventContent.ID));
        }
        public HttpResponseMessage CreateEvent(Event newEvent)
        {
            if (newEvent == null)
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentNullException("newEvent"));

            try
            {
                eventService.AddEvent(newEvent);
                var response = Request.CreateResponse(HttpStatusCode.Created, newEvent);
                response.Headers.Location = new Uri(Request.RequestUri.Scheme + "://" + Request.RequestUri.Authority + "/api/events/byid?eventID=" + newEvent.ID);
                return response;
            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
            }
        }
 private static void writeItem(Event evt, StreamWriter writer)
 {
     writer.WriteLine("{0},{1},{2},{3},{4},{5}", evt.ID, evt.Host, evt.Title, evt.Description, evt.StartDateTime, evt.Address);
 }
 public void AddEvent(Event newEvent)
 {
     this.eventsRepo.InsertOrUpdate(newEvent);
     this.eventsRepo.Save();
 }