Example #1
0
        public void should_store_and_retrieve_event()
        {
            // Arrange
            var serializer = new EventsSerializer("test.xml");
            var repository = new EventsRepository(serializer);
            var dt = new DateTime(2012, 7, 14);

            // Act
            repository.Add(new Event(dt));
            var list = repository.GetAll();

            // Assert
            Assert.Equal(1, list.Count);
            Assert.Equal(dt, list[0].Date);
        }
        public ActionResult Add(Event ev)
        {
            ValidateEvent(ev);

            if (ModelState.IsValid)
            {
                _eventsRepository.Add(ev);

                TempData["Message"] = "Your event was successfully added!";

                return(RedirectToAction("Detail", new { id = ev.Id }));
            }

            return(View(ev));
        }
Example #3
0
        static void Main(string[] args)
        {
            Event ev = new Event();

            Events.Funct f = new Events.Funct(PrintNumber);
            ev.Subscribe(f);
            EventsRepository repo = new EventsRepository();

            repo.Add(ev);

            repo.GetEvent(0).Trigger(5);


            Console.ReadLine();
        }
        public ActionResult Post([FromBody] NewEventViewModel newEvent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var id  = _eventRepo.GetNextId();
            var eve = new Event(id, newEvent.Name, newEvent.Description, newEvent.Price, newEvent.DateTime, newEvent.AdditionalInformation);

            try
            {
                _eventRepo.Add(eve);
                var viewModel = new EventDetailsViewModel(eve.Id, eve.Name, eve.Description, eve.Date, eve.Price, eve.AdditionalInformation);
                return(CreatedAtRoute("GetById", new { id = eve.Id }, viewModel));
            }
            catch (Exception)
            {
                return(StatusCode(500, "There was an error handling your request."));
            }
        }