public RequestTransactionAndEventing(ConferenceContext context, IMediator mediator,
                                      ILogger <RequestTransactionAndEventing <TRequest, TResponse> > logger)
 {
     this.context  = context;
     this.mediator = mediator;
     this.logger   = logger;
 }
        protected override void Initialize(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);
            ConferenceContext context = new ConferenceContext();

            DomainManager = new EntityDomainManager <Category>(context, Request, true);
        }
Exemple #3
0
 private Order FindOrder(Guid orderId)
 {
     using (var context = new ConferenceContext(dbName))
     {
         return(context.Orders.Include(x => x.Seats).FirstOrDefault(x => x.Id == orderId));
     }
 }
 public void Then_conference_is_created_unpublished()
 {
     using (var context = new ConferenceContext(this._dbName)) {
         Assert.IsFalse(context.Conferences.Find(this._conference.Id).IsPublished);
         Assert.IsFalse(context.Conferences.Find(this._conference.Id).WasEverPublished);
     }
 }
        // POST api/Announcement

        public async Task <HttpResponseMessage> Post(string password, [FromBody] string message)
        {
            HttpStatusCode ret = HttpStatusCode.InternalServerError;

            if (string.IsNullOrWhiteSpace(message) || password != ConfigurationManager.AppSettings["NotificationsPassword"])
            {
                return(Request.CreateResponse(ret));
            }


            try
            {
                var accounenement = new Notification
                {
                    Date = DateTime.UtcNow,
                    Text = message
                };

                var context = new ConferenceContext();

                context.Notifications.Add(accounenement);

                await context.SaveChangesAsync();
            }
            catch
            {
                return(Request.CreateResponse(ret));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Exemple #6
0
        public async Task <IHttpActionResult> StoreRatings([FromBody] IEnumerable <SessionRatingDto> ratings)
        {
            using (var context = new ConferenceContext())
            {
                foreach (var rating in ratings.Where(r => r.Rating > 0))
                {
                    var existingRating = await context.Ratings.Include("Ticket").Include("Session").FirstOrDefaultAsync(
                        rate => rate.Ticket.TicketId == rating.TicketId && rate.Session.SessionId == rating.SessionId);

                    if (existingRating == null)
                    {
                        var ticket = await context.Tickets.FirstOrDefaultAsync(t => t.TicketId == rating.TicketId);

                        var session = await context.Sessions.FirstOrDefaultAsync(s => s.SessionId == rating.SessionId);

                        var newRating = new SessionRating()
                        {
                            Ticket = ticket, Session = session, Rating = rating.Rating
                        };
                        context.Ratings.Add(newRating);
                    }
                    else
                    {
                        existingRating.Rating = rating.Rating;
                        context.Entry(existingRating).State = EntityState.Modified;
                    }

                    await context.SaveChangesAsync();
                }
            }

            return(this.Ok());
        }
		public async Task<IHttpActionResult> StoreRatings([FromBody]IEnumerable<SessionRatingDto> ratings)
		{
			using (var context = new ConferenceContext())
			{
				foreach (var rating in ratings.Where(r => r.Rating > 0))
				{
					var existingRating = await context.Ratings.Include("Ticket").Include("Session").FirstOrDefaultAsync(
						rate => rate.Ticket.TicketId == rating.TicketId && rate.Session.SessionId == rating.SessionId);
					if (existingRating == null)
					{
						var ticket = await context.Tickets.FirstOrDefaultAsync(t => t.TicketId == rating.TicketId);
						var session = await context.Sessions.FirstOrDefaultAsync(s => s.SessionId == rating.SessionId);

						var newRating = new SessionRating() { Ticket = ticket, Session = session, Rating = rating.Rating };
						context.Ratings.Add(newRating);
					}
					else
					{
						existingRating.Rating = rating.Rating;
						context.Entry(existingRating).State = EntityState.Modified;
					}

					await context.SaveChangesAsync();
				}
			}

			return this.Ok();
		}
Exemple #8
0
 public ActionResult Index()
 {
     using (ConferenceContext context = new ConferenceContext())
     {
         return View(context.Sessions.ToList());
     }
 }
 public static ConferenceInfo FindConference(string conferenceSlug)
 {
     using (var context = new ConferenceContext("ConferenceManagement"))
     {
         return context.Conferences.Include(x => x.Seats).FirstOrDefault(x => x.Slug == conferenceSlug);
     }
 }
Exemple #10
0
 public void Register(int sessionid)
 {
     using (var ctx = new ConferenceContext())
     {
         Groups.Add(ctx.Database.Connection.ConnectionString, sessionid.ToString());
     }
 }
Exemple #11
0
        public async Task <ActionResult> Details(int id)
        {
            var model = new ConferenceDetailsViewModel();

            //1. First fetch the conference details form the database.
            using (var db = new ConferenceContext())
            {
                var conference = db.Conferences.FirstOrDefault(c => c.Id == id);
                if (conference != null)
                {
                    model.Conference = conference;
                }
            }

            try
            {
                var conf = await Getconference(model.Conference.ConferenceId.ToString()).Get();

                // store the participants in the result model
                model.Participants = conf.Participants;
            }
            catch (Exception)
            {
                model.Participants = new IParticipant[0];
                //do nothing, just means no one is in the conference
            }


            return(View(model));
        }
Exemple #12
0
        private static void InsertData()
        {
            using (var context = new ConferenceContext())
            {
                context.Database.EnsureCreated();

                var section1 = new SectionEntry
                {
                    Section  = "GIS",
                    City     = "Tomsk",
                    Name     = "Geoinformation Systems",
                    Location = "Lenina 2, 404"
                };

                var section2 = new SectionEntry
                {
                    Section  = "CS",
                    City     = "Tomsk",
                    Name     = "Computer Science",
                    Location = "Lenina 30, 206"
                };

                if (!context.SectionEntry.Any(s => s.Section == section1.Section))
                {
                    context.SectionEntry.Add(section1);
                }
                if (!context.SectionEntry.Any(s => s.Section == section2.Section))
                {
                    context.SectionEntry.Add(section2);
                }

                context.SaveChanges();
            }
        }
Exemple #13
0
 public void then_conference_is_persisted()
 {
     using (var context = new ConferenceContext(this.dbName))
     {
         Assert.NotNull(context.Conferences.Find(this.conference.Id));
     }
 }
 public void then_conference_is_created_unpublished()
 {
     using (var context = new ConferenceContext()) {
         Assert.False(context.Conferences.Find(conference.Id).IsPublished);
         Assert.False(context.Conferences.Find(conference.Id).WasEverPublished);
     }
 }
        public ActionResult Details(Int32 id)
        {
            ConferenceContext context = new ConferenceContext();
            List <Session>    sesions = context.Sessions.Where(s => s.SessionId == id).ToList();

            return(View(sesions[0]));
        }
Exemple #16
0
 public RepositoryManager(string connectionString)
 {
     _ctx               = new ConferenceContext(connectionString);
     UserManager        = new ApplicationUserManager(new UserStore <ApplicationUser>(_ctx));
     RoleMaanger        = new ApplicationRoleManager(new RoleStore <ApplicationRole>(_ctx));
     UserProfileManager = new UserProfileManager(_ctx);
 }
        // GET: Session
        public ActionResult Index()
        {
            ConferenceContext context = new ConferenceContext();
            List <Session>    sesions = context.Sessions.ToList();

            return(View(sesions));
        }
 public static ConferenceInfo FindConference(string conferenceSlug)
 {
     using (var context = new ConferenceContext("ConferenceManagement"))
     {
         return(context.Conferences.Include(x => x.Seats).FirstOrDefault(x => x.Slug == conferenceSlug));
     }
 }
        public async Task <IActionResult> PutSession(int id, Session session)
        {
            if (id != session.Id)
            {
                return(BadRequest());
            }

            var context = new ConferenceContext();

            context.Entry(session).State = EntityState.Modified;

            try
            {
                await context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await SessionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #20
0
 public ActionResult Index()
 {
     using (var db = new ConferenceContext())
     {
         var model = db.Conferences.ToList();
         return(View(model));
     }
 }
 public void Dispose()
 {
     using (var context = new ConferenceContext(dbName))
     {
         if (context.Database.Exists())
             context.Database.Delete();
     }
 }
Exemple #22
0
        // Very similar to ConferenceService.cs
        private IEnumerable <IEvent> GenerateMissedConferenceManagementIntegrationEvents(string nameOrConnectionString)
        {
            // Note: instead of returning a list, could yield results if data set is very big. Seems unnecessary.
            var events = new List <IEvent>();

            using (var context = new ConferenceContext(nameOrConnectionString))
            {
                foreach (var conference in context.Conferences.Include(x => x.Seats))
                {
                    // Use automapper? I'd prefer this to be explicit just in case we don't make mistakes with versions.
                    events.Add(new ConferenceCreated
                    {
                        SourceId = conference.Id,
                        Owner    = new Owner
                        {
                            Name  = conference.OwnerName,
                            Email = conference.OwnerEmail,
                        },
                        Name          = conference.Name,
                        Description   = conference.Description,
                        Location      = conference.Location,
                        Slug          = conference.Slug,
                        Tagline       = conference.Tagline,
                        TwitterSearch = conference.TwitterSearch,
                        StartDate     = conference.StartDate,
                        EndDate       = conference.EndDate,
                    });

                    foreach (var seat in conference.Seats)
                    {
                        events.Add(new SeatCreated
                        {
                            ConferenceId = conference.Id,
                            SourceId     = seat.Id,
                            Name         = seat.Name,
                            Description  = seat.Description,
                            Price        = seat.Price,
                            Quantity     = seat.Quantity
                        });
                    }

                    if (conference.WasEverPublished)
                    {
                        events.Add(new ConferencePublished {
                            SourceId = conference.Id
                        });
                        if (!conference.IsPublished)
                        {
                            events.Add(new ConferenceUnpublished {
                                SourceId = conference.Id
                            });
                        }
                    }
                }
            }

            return(events);
        }
Exemple #23
0
        private static void Main(string[] args)
        {
            var connectionString = ConfigurationManager.AppSettings["defaultConnection"];

            if (args.Length > 0)
            {
                connectionString = args[0];
            }

            // Use ConferenceContext as entry point for dropping and recreating DB
            using (var context = new ConferenceContext()) {
                if (context.Database.Exists())
                {
                    context.Database.Delete();
                }
                context.Database.Create();
            }

            Database.SetInitializer <EventStoreDbContext>(null);
            Database.SetInitializer <MessageLogDbContext>(null);
            Database.SetInitializer <BlobStorageDbContext>(null);
            Database.SetInitializer <ConferenceRegistrationDbContext>(null);
            Database.SetInitializer <RegistrationProcessManagerDbContext>(null);
            Database.SetInitializer <PaymentsDbContext>(null);

            DbContext[] contexts =
            {
                new EventStoreDbContext(connectionString),
                new MessageLogDbContext(connectionString),
                new BlobStorageDbContext(connectionString),
                new PaymentsDbContext(connectionString),
                new RegistrationProcessManagerDbContext(connectionString),
                new ConferenceRegistrationDbContext(connectionString)
            };

            foreach (var context in contexts)
            {
                var adapter = (IObjectContextAdapter)context;
                var script  = adapter.ObjectContext.CreateDatabaseScript();
                context.Database.ExecuteSqlCommand(script);
                context.Dispose();
            }

            using (var context = new ConferenceRegistrationDbContext(connectionString)) {
                ConferenceRegistrationDbContextInitializer.CreateIndexes(context);
            }

            using (var context = new RegistrationProcessManagerDbContext(connectionString)) {
                RegistrationProcessManagerDbContextInitializer.CreateIndexes(context);
            }

            using (var context = new PaymentsDbContext(connectionString)) {
                PaymentsReadDbContextInitializer.CreateViews(context);
            }

            MessagingDbInitializer.CreateDatabaseObjects(connectionString, "SqlBus");
        }
Exemple #24
0
 public Validator(ConferenceContext context)
 {
     RuleFor(command => command.Name)
     .NotEmpty()
     .WithMessage("Conference name cannot be empty.");
     RuleFor(command => command.Name)
     .Must(context.ThereIsNoConferenceWithGivenName)
     .WithMessage("There is already conference with given name.");
 }
 public void Dispose()
 {
     using (var context = new ConferenceContext()) {
         if (context.Database.Exists())
         {
             context.Database.Delete();
         }
     }
 }
Exemple #26
0
 public void TearDown()
 {
     using (var context = new ConferenceContext(this._dbName)) {
         if (context.Database.Exists())
         {
             context.Database.Delete();
         }
     }
 }
		public async Task<IHttpActionResult> SaveTicket(Ticket ticket)
		{
			using (var context = new ConferenceContext())
			{
				context.Entry(ticket).State = EntityState.Modified;
				await context.SaveChangesAsync();
				return this.Ok();
			}
		}
Exemple #28
0
        public void Setup()
        {
            // 初始化会议数据库
            using (var context = new ConferenceContext(this._dbName)) {
                if (context.Database.Exists())
                {
                    context.Database.Delete();
                }
                context.Database.Create();
            }

            // 模拟事件总线
            this._busEvents = new List <IEvent>();
            var busMock = new Mock <IEventBus>();

            busMock.Setup(b => b.Publish(It.IsAny <Envelope <IEvent> >()))
            .Callback <Envelope <IEvent> >(e => this._busEvents.Add(e.Body));
            busMock.Setup(b => b.Publish(It.IsAny <IEnumerable <Envelope <IEvent> > >()))
            .Callback <IEnumerable <Envelope <IEvent> > >(es => this._busEvents.AddRange(es.Select(e => e.Body)));

            this._service = new ConferenceService(busMock.Object, this._dbName);

            this._conference = new ConferenceInfo()
            {
                OwnerEmail  = "*****@*****.**",
                OwnerName   = "test owner",
                AccessCode  = "qwerty",
                Name        = "test conference",
                Description = "test conference description",
                Location    = "redmond",
                Slug        = "test",
                StartDate   = DateTime.UtcNow,
                EndDate     = DateTime.UtcNow.Add(TimeSpan.FromDays(2)),
                Seats       =
                {
                    new SeatType()
                    {
                        Name        = "general",
                        Description = "general description",
                        Price       = 100,
                        Quantity    = 10
                    }
                }
            };

            this._service.CreateConference(this._conference);

            this._placed = new OrderPlaced()
            {
                ConferenceId = Guid.NewGuid(),
                SourceId     = Guid.NewGuid(),
                AccessCode   = "asdf"
            };

            this._eventHandler = new OrderEventHandler(() => new ConferenceContext(_dbName));
            this._eventHandler.Handle(_placed);
        }
        public async Task <ActionResult <Session> > PostSession(Session session)
        {
            var context = new ConferenceContext();

            context.Sessions.Add(session);
            await context.SaveChangesAsync();

            return(CreatedAtAction("GetSession", new { id = session.Id }, session));
        }
Exemple #30
0
        public async Task <IHttpActionResult> SaveTicket(Ticket ticket)
        {
            using (var context = new ConferenceContext())
            {
                context.Entry(ticket).State = EntityState.Modified;
                await context.SaveChangesAsync();

                return(this.Ok());
            }
        }
Exemple #31
0
 public AddEditConferenceUserViewModel()
 {
     using (var context = new ConferenceContext())
     {
         City = context.City
                .Select(x => new SelectListItem {
             Text = x.CityName, Value = x.Id.ToString()
         })
                .ToArray();
     }
 }
Exemple #32
0
        public void AddComment(int sessionid, string content)
        {
            using (var ctx = new ConferenceContext())
            {
                Comment comment = new Comment { SessionId = sessionid, Content = content };
                ctx.Comments.Add(comment);
                ctx.SaveChanges();

                Clients.Group(sessionid.ToString()).AddNewComment(content);
            }
        }
Exemple #33
0
        public void Setup()
        {
            using (var context = new ConferenceContext(_dbName)) {
                if (context.Database.Exists())
                {
                    context.Database.Delete();
                }
                context.Database.Create();
            }

            this._eventHandler = new OrderEventHandler(() => new ConferenceContext(_dbName));
        }
Exemple #34
0
 public async Task <RedirectToRouteResult> Create(Conference model)
 {
     using (var db = new ConferenceContext()) {
         // lets add a new guid to the model to ensure that all conferences are uniq
         model.ConferenceId = Guid.NewGuid();
         //save it
         db.Conferences.Add(model);
         await db.SaveChangesAsync();
     }
     //return tohome controller
     return(RedirectToAction("Index"));
 }
        public async Task <ActionResult <Session> > GetSession(int id)
        {
            var context = new ConferenceContext();
            var session = await context.Sessions.FindAsync(id);

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

            return(session);
        }
        public given_no_order()
        {
            using (var context = new ConferenceContext(dbName))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.Create();
            }

            this.sut = new OrderEventHandler(() => new ConferenceContext(dbName));
        }
        public given_no_conference()
        {
            using (var context = new ConferenceContext(dbName))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.CreateIfNotExists();
            }

            this.bus = new MemoryEventBus();
            this.service = new ConferenceService(this.bus, this.dbName);
        }
        public given_no_order()
        {
            using (var context = new ConferenceContext()) {
                if (context.Database.Exists())
                {
                    context.Database.Delete();
                }

                context.Database.Create();
            }

            sut = new OrderEventHandler(() => new ConferenceContext());
        }
		public async Task<IHttpActionResult> GetTicket(string ticketId)
		{
			using (var context = new ConferenceContext())
			{
				var ticket = await context.Tickets.FirstOrDefaultAsync(t => t.TicketId == ticketId);
				if (ticket == null)
				{
					return this.NotFound();
				}

				return this.Ok(ticket);
			}
		}
		public async Task<IHttpActionResult> GetSessions()
		{
			using (var context = new ConferenceContext())
			{
				var sessions = await context.Sessions.ToArrayAsync();
				if (sessions.Length == 0)
				{
					return this.NotFound();
				}

				return this.Ok(sessions);
			}
		}
        public given_no_conference()
        {
            using (var context = new ConferenceContext(dbName))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.Create();
            }

            this.busEvents = new List<IEvent>();
            var busMock = new Mock<IEventBus>();
            busMock.Setup(b => b.Publish(It.IsAny<Envelope<IEvent>>())).Callback<Envelope<IEvent>>(e => busEvents.Add(e.Body));
            busMock.Setup(b => b.Publish(It.IsAny<IEnumerable<Envelope<IEvent>>>())).Callback<IEnumerable<Envelope<IEvent>>>(es => busEvents.AddRange(es.Select(e => e.Body)));

            this.service = new ConferenceService(busMock.Object, this.dbName);
        }
        public void CreateFromScratch()
        {
            var connectionString = "Data Source=localhost\\sqlexpress;Initial Catalog=Session_" + Guid.NewGuid().ToString() + ";Trusted_Connection=True;";
            try
            {
                var dbConnection = new DbConnectionInfo(connectionString, "System.Data.SqlClient");
                var settings = new Model.Migrations.Configuration();
                settings.TargetDatabase = dbConnection;
                var migrator = new DbMigrator(settings);

                migrator.Update(targetMigration: "201307170913098_AddedUserIsDeletedField");
            }
            finally
            {
                var context = new ConferenceContext(connectionString);
                context.Database.Delete();
            }
        }
        public void when_order_placed_then_creates_order_entity()
        {
            var e = new OrderPlaced
            {
                ConferenceId = Guid.NewGuid(),
                SourceId = Guid.NewGuid(),
                AccessCode = "asdf",
            };

            this.sut.Handle(e);

            using (var context = new ConferenceContext(dbName))
            {
                var order = context.Orders.Find(e.SourceId);

                Assert.NotNull(order);
            }
        }
        public given_an_existing_conference_with_a_seat()
        {
            using (var context = new ConferenceContext(dbName))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.CreateIfNotExists();
            }

            this.busEvents = new List<IEvent>();
            var busMock = new Mock<IEventBus>();
            busMock.Setup(b => b.Publish(It.IsAny<Envelope<IEvent>>())).Callback<Envelope<IEvent>>(e => busEvents.Add(e.Body));
            busMock.Setup(b => b.Publish(It.IsAny<IEnumerable<Envelope<IEvent>>>())).Callback<IEnumerable<Envelope<IEvent>>>(es => busEvents.AddRange(es.Select(e => e.Body)));
            this.service = new ConferenceService(busMock.Object, this.dbName);
            this.conference = new ConferenceInfo
            {
                OwnerEmail = "*****@*****.**",
                OwnerName = "test owner",
                AccessCode = "qwerty",
                Name = "test conference",
                Description = "test conference description",
                Location = "redmond",
                Slug = "test",
                StartDate = DateTime.UtcNow,
                EndDate = DateTime.UtcNow.Add(TimeSpan.FromDays(2)),
                IsPublished = true,
                Seats = 
                {
                    new SeatType
                    {
                        Name = "general", 
                        Description = "general description", 
                        Price = 100, 
                        Quantity = 10,
                    }
                }
            };
            service.CreateConference(this.conference);
        }
        public given_an_existing_conference_with_a_seat()
        {
            using (var context = new ConferenceContext(dbName))
            {
                if (context.Database.Exists())
                    context.Database.Delete();

                context.Database.CreateIfNotExists();
            }

            this.bus = new MemoryEventBus();
            this.service = new ConferenceService(this.bus, this.dbName);
            this.conference = new ConferenceInfo
            {
                OwnerEmail = "*****@*****.**",
                OwnerName = "test owner",
                AccessCode = "qwerty",
                Name = "test conference",
                Description = "test conference description",
                Location = "redmond",
                Slug = "test",
                StartDate = DateTime.UtcNow,
                EndDate = DateTime.UtcNow.Add(TimeSpan.FromDays(2)),
                IsPublished = true,
                Seats = 
                {
                    new SeatType
                    {
                        Name = "general", 
                        Description = "general description", 
                        Price = 100, 
                        Quantity = 10,
                    }
                }
            };
            service.CreateConference(this.conference);
        }
 private Order FindOrder(Guid orderId)
 {
     using (var context = new ConferenceContext(dbName))
     {
         return context.Orders.Include(x => x.Seats).FirstOrDefault(x => x.Id == orderId);
     }
 }
 public void then_conference_is_persisted()
 {
     using (var context = new ConferenceContext(this.dbName))
     {
         Assert.NotNull(context.Conferences.Find(this.conference.Id));
     }
 }
 public void then_conference_is_created_unpublished()
 {
     using (var context = new ConferenceContext(this.dbName))
     {
         Assert.False(context.Conferences.Find(this.conference.Id).IsPublished);
         Assert.False(context.Conferences.Find(this.conference.Id).WasEverPublished);
     }
 }