Пример #1
0
 /// <summary>
 /// 获取所有商户
 /// </summary>
 /// <returns></returns>
 public IQueryable <SportsCenter> GetSportsCenters()
 {
     using (SportsContext db = new SportsContext())
     {
         return(db.SportsCenters);
     }
 }
 // GET: api/BookSiteTempletes
 public IQueryable <BookSiteTemplete> GetBookSiteTempletes()
 {
     using (SportsContext db = new SportsContext())
     {
         return(db.BookSiteTempletes);
     }
 }
Пример #3
0
 // GET: api/Sites
 public IQueryable <Site> GetSites()
 {
     using (SportsContext db = new SportsContext())
     {
         return(db.Sites);
     }
 }
Пример #4
0
 // GET: api/SiteBookStatus
 public IQueryable <SiteBookStatus> GetSiteBookStatus()
 {
     using (SportsContext db = new SportsContext())
     {
         return(db.SiteBookStatus);
     }
 }
Пример #5
0
 // GET: api/SportCategories
 public IQueryable <SportCategory> GetSportCategories()
 {
     using (SportsContext db = new SportsContext())
     {
         return(db.SportCategories);
     }
 }
Пример #6
0
        public async Task <IHttpActionResult> PutSiteBookStatus(Guid id, SiteBookStatus siteBookStatus)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != siteBookStatus.Id)
            {
                return(BadRequest());
            }

            using (SportsContext db = new SportsContext())
            {
                db.Entry(siteBookStatus).State = EntityState.Modified;

                try
                {
                    await db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (db.SiteBookStatus.Count(e => e.Id == id) <= 0)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(StatusCode(HttpStatusCode.NoContent));
            }
        }
Пример #7
0
 public BookingService(SportsContext context, IBookingLineService bookingLineService, IBookingFormService bookingFormService, IPDFService <Booking> pdfService, ISpotService spotService) : base(context)
 {
     _bookingLineService = bookingLineService;
     _bookingFormService = bookingFormService;
     _pdfService         = pdfService;
     _spotService        = spotService;
 }
Пример #8
0
 public SyncServiceTests(SportsFixture sportsFixture, ITestOutputHelper testOutputHelper)
     : base(testOutputHelper)
 {
     _syncService = sportsFixture.SyncService;
     _newsService = sportsFixture.NewsService;
     _newsArticleCommentService = sportsFixture.NewsArticleCommentService;
     _sportsContext             = sportsFixture.SportsContext;
 }
 private void Seed()
 {
     using (var context = new SportsContext(ContextOptions))
     {
         context.Database.EnsureDeleted();
         DbInitializer.SeedDb(context);
     }
 }
Пример #10
0
 public SyncService(SportsContext sportsContext, ISportsRuApiService sportsRuApiService
                    , INewsArticleDataService newsArticleDataService, ILogger <SyncService> logger)
 {
     _sportsContext          = sportsContext;
     _sportsRuApiService     = sportsRuApiService;
     _newsArticleDataService = newsArticleDataService;
     _logger = logger;
 }
        public async Task <IHttpActionResult> GetBookSiteTemplete(Guid id)
        {
            using (SportsContext db = new SportsContext())
            {
                BookSiteTemplete bookSiteTemplete = await db.BookSiteTempletes.FindAsync(id);

                if (bookSiteTemplete == null)
                {
                    return(NotFound());
                }
                return(Ok(bookSiteTemplete));
            }
        }
Пример #12
0
        public async Task <IHttpActionResult> GetSite(Guid id)
        {
            using (SportsContext db = new SportsContext())
            {
                Site site = await db.Sites.FindAsync(id);

                if (site == null)
                {
                    return(NotFound());
                }
                return(Ok(site));
            }
        }
Пример #13
0
        public async Task <IHttpActionResult> GetSportCategory(Guid id)
        {
            using (SportsContext db = new SportsContext())
            {
                SportCategory sportCategory = await db.SportCategories.FindAsync(id);

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

                return(Ok(sportCategory));
            }
        }
Пример #14
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, SportsContext context)
        {
            if (env.IsDevelopment())
            {
                // When the app runs in the Development environment:
                //   Use the Developer Exception Page to report app runtime errors.
                //   Use the Database Error Page to report database runtime errors.
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();

                // Seed data for In Memory EF Context
                //   REMOVE SportsContext from Configure() parameter list when done w/ In Memory
                InMemoryDataSeeder.Instance.Seed(context);
            }
            else
            {
                // When the app doesn't run in the Development environment:
                //   Enable the Exception Handler Middleware to catch exceptions
                //app.UseExceptionHandler("/Error");
            }

            app.UseStatusCodePages();

            // Use HTTPS Redirection Middleware to redirect HTTP requests to HTTPS.
            //app.UseHttpsRedirection();

            // Return static files and end the pipeline.
            app.UseStaticFiles();

            // Use Cookie Policy Middleware to conform to EU General Data
            // Protection Regulation (GDPR) regulations.
            //app.UseCookiePolicy();

            // Authenticate before the user accesses secure resources.
            //app.UseAuthentication();

            // If the app uses session state, call Session Middleware after Cookie
            // Policy Middleware and before MVC Middleware.
            app.UseSession();

            // Add MVC to the request pipeline.
            //app.UseMvcWithDefaultRoute();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}"
                    );
            });
        }
Пример #15
0
        public async Task <IHttpActionResult> GetSportsCenter(Guid id)
        {
            using (SportsContext db = new SportsContext())
            {
                SportsCenter sportsCenter = await db.SportsCenters.FindAsync(id);

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

                return(Ok(sportsCenter));
            }
        }
Пример #16
0
        public async Task <IHttpActionResult> PostSite(Site site)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            using (SportsContext db = new SportsContext())
            {
                db.Sites.Add(site);
                await db.SaveChangesAsync();

                return(CreatedAtRoute("DefaultApi", new { id = site.SiteId }, site));
            }
        }
Пример #17
0
        public async Task <IHttpActionResult> PostSportsCenter(SportsCenter sportsCenter)
        {
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges <SportsContext>());
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            using (SportsContext db = new SportsContext())
            {
                db.SportsCenters.Add(sportsCenter);
                int effetiveRow = await db.SaveChangesAsync();
            }

            return(CreatedAtRoute("DefaultApi", new { id = sportsCenter.CenterId }, sportsCenter));
        }
Пример #18
0
        public async Task <IHttpActionResult> DeleteSiteBookStatus(Guid id)
        {
            using (SportsContext db = new SportsContext())
            {
                SiteBookStatus siteBookStatus = await db.SiteBookStatus.FindAsync(id);

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

                db.SiteBookStatus.Remove(siteBookStatus);
                await db.SaveChangesAsync();

                return(Ok(siteBookStatus));
            }
        }
Пример #19
0
        public async Task <IHttpActionResult> Delete(Guid id)
        {
            using (SportsContext db = new SportsContext())
            {
                SportsCenter sportsCenter = await db.SportsCenters.FindAsync(id);

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

                db.SportsCenters.Remove(sportsCenter);
                await db.SaveChangesAsync();

                return(Ok(sportsCenter));
            }
        }
        public async Task <IHttpActionResult> DeleteBookSiteTemplete(Guid id)
        {
            using (SportsContext db = new SportsContext())
            {
                BookSiteTemplete bookSiteTemplete = await db.BookSiteTempletes.FindAsync(id);

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

                db.BookSiteTempletes.Remove(bookSiteTemplete);
                await db.SaveChangesAsync();

                return(Ok(bookSiteTemplete));
            }
        }
Пример #21
0
        public void OneTimeInit()
        {
            this.comparer = new TeamDtoComparer();
            AutoMapperConfiguration.Configure();

            this.databaseSportsContext = new SportsContext("SportsContext");

            // Clear tables
            this.databaseSportsContext.TeamNames.RemoveRange(
                this.databaseSportsContext.TeamNames);
            this.databaseSportsContext.Results.RemoveRange(
                this.databaseSportsContext.Results);
            this.databaseSportsContext.SportEvents.RemoveRange(
                this.databaseSportsContext.SportEvents);
            this.databaseSportsContext.Teams.RemoveRange(
                this.databaseSportsContext.Teams);
            this.databaseSportsContext.SportTypes.RemoveRange(
                this.databaseSportsContext.SportTypes);
            this.databaseSportsContext.SaveChanges();

            this.databaseSportsContext.Database.ExecuteSqlCommand(
                @"SET IDENTITY_INSERT [dbo].[SportTypes] ON;
                INSERT INTO [dbo].[SportTypes] ([Id], [Name])
                VALUES
                (1, 'Football'),
                (2, 'Basketball');               
                SET IDENTITY_INSERT [dbo].[SportTypes] OFF;");

            this.databaseSportsContext.Database.ExecuteSqlCommand(
                @"SET IDENTITY_INSERT [dbo].[Teams] ON;
                INSERT INTO [dbo].[Teams] ([Id], [Name], [SportType_Id])
                VALUES
                (1, 'Manchester United', 1),
                (2, 'Milano', 1),
                (3, 'Manchester City', 1),
                (4, 'Chelsea', 1),
                (5, 'Bayern', 1),
                (6, 'Chicago Bulls', 2),
                (7, 'Los Angeles Lakers', 2),
                (8, 'Phoenix Suns', 2);               
                SET IDENTITY_INSERT [dbo].[Teams] OFF;");

            this.databaseSportsContext.SaveChanges();
            this.teamService = new TeamService(new EFUnitOfWork(this.databaseSportsContext));
        }
Пример #22
0
        public void TestCreation()
        {
            var builder = new DbContextOptionsBuilder();

            builder
            .UseLazyLoadingProxies()
            .UseSqlite("Data Source=sports.db");
            using var db = new SportsContext(builder.Options);
            db.Database.EnsureDeleted();
            db.Database.EnsureCreated();
            var article = new NewsArticle()
            {
                Title = "test"
            };

            db.NewsArticles.Add(article);
            db.SaveChanges();
            Assert.NotEqual(Guid.Empty, article.NewsArticleId);
        }
Пример #23
0
        public SportsContext CreateContext(DbTransaction transaction = null)
        {
            SportsContext context;

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // Using Sqlite for linux here
                context = new SportsContext(new DbContextOptionsBuilder <SportsContext>().UseSqlite(Connection).Options);
            }
            else
            {
                context = new SportsContext(new DbContextOptionsBuilder <SportsContext>().UseSqlServer(Connection).Options);
            }

            if (transaction != null)
            {
                context.Database.UseTransaction(transaction);
            }

            return(context);
        }
Пример #24
0
        public SportsFixture()
        {
            var builder = new DbContextOptionsBuilder();

            builder
            .UseLazyLoadingProxies()
            .UseSqlite("Data Source=sports.db");
            SportsContext = new SportsContext(builder.Options);
            SportsContext.Database.EnsureDeleted();
            SportsContext.Database.EnsureCreated();

            var sportsRuLogger      = Mock.Of <ILogger <SportsRuApiService> >();
            var sportsRuApiSettings = new SportsRuApiSettings("https://www.sports.ru", "https://stat.sports.ru");
            ISportsRuApiService sportsRuApiService = new SportsRuApiService(sportsRuApiSettings, sportsRuLogger);
            var newsArticleDataService             = new NewsArticleDataService(SportsContext);

            NewsService = new NewsService(SportsContext, newsArticleDataService);
            var syncServiceLogger = Mock.Of <ILogger <SyncService> >();

            SyncService = new SyncService(SportsContext, sportsRuApiService, newsArticleDataService, syncServiceLogger);
            NewsArticleCommentService = new NewsArticleCommentService(SportsContext);
        }
Пример #25
0
        public void OneTimeInit()
        {
            this.databaseSportsContext = new SportsContext("SportsContext");

            //// Other transactions can't update and insert data
            //this.databaseTransaction = this.databaseSportsContext
            //    .Database.BeginTransaction(IsolationLevel.Serializable);

            // Clear tables
            this.databaseSportsContext.TeamNames.RemoveRange(
                this.databaseSportsContext.TeamNames);
            this.databaseSportsContext.Results.RemoveRange(
                this.databaseSportsContext.Results);
            this.databaseSportsContext.SportEvents.RemoveRange(
                this.databaseSportsContext.SportEvents);
            this.databaseSportsContext.Teams.RemoveRange(
                this.databaseSportsContext.Teams);
            this.databaseSportsContext.SportTypes.RemoveRange(
                this.databaseSportsContext.SportTypes);

            this.databaseSportsContext.SaveChanges();

            this.eventService = new EventsService(new EFUnitOfWork(this.databaseSportsContext));
            this.comparer     = new ResultDtoComparer();

            AutoMapperConfiguration.Configure();

            this.databaseSportsContext.Database.ExecuteSqlCommand(
                @"SET IDENTITY_INSERT [dbo].[SportTypes] ON;
                INSERT INTO [dbo].[SportTypes] ([Id], [Name])
                VALUES
                (1, 'Football'),
                (2, 'Basketball'),
                (3, 'Hockey');               
                SET IDENTITY_INSERT [dbo].[SportTypes] OFF;");

            this.databaseSportsContext.Database.ExecuteSqlCommand(
                @"SET IDENTITY_INSERT [dbo].[Teams] ON;
                INSERT INTO [dbo].[Teams] ([Id], [Name], [SportType_Id])
                VALUES
                (1, 'Manchester United', 1),
                (2, 'Milano', 1),
                (3, 'Manchester City', 1),
                (4, 'Chelsea', 1),
                (5, 'Bayern', 1),
                (6, 'Chicago Bulls', 2),
                (7, 'Los Angeles Lakers', 2),
                (8, 'Phoenix Suns', 2);               
                SET IDENTITY_INSERT [dbo].[Teams] OFF;");

            this.databaseSportsContext.Database.ExecuteSqlCommand(
                @"SET IDENTITY_INSERT [dbo].[TeamNames] ON;
                INSERT INTO [dbo].[TeamNames] ([Id], [Name], [Team_Id])
                VALUES
                (1, 'Manchester United', 1),
                (2, 'Milano', 2),
                (3, 'Manchester City', 3),
                (4, 'Chelsea', 4),
                (5, 'Bayern', 5),
                (6, 'Chicago Bulls', 6),
                (7, 'Los Angeles Lakers', 7),
                (8, 'Phoenix Suns', 8);               
                SET IDENTITY_INSERT [dbo].[TeamNames] OFF;");

            this.databaseSportsContext.Database.ExecuteSqlCommand(
                @"SET IDENTITY_INSERT [dbo].[SportEvents] ON;
                INSERT INTO [dbo].[SportEvents] ([Id], [Date], [SportType_Id])
                VALUES
                (1, '20161119 17:00', 1),
                (2, '20161028 17:00', 1),
                (3, '20161017 18:00', 1),
                (4, '20161103 16:00', 1),
                (5, '20161105 16:00', 2),
                (6, '20161129 16:00', 2),
                (7, '20161115 16:00', 2);               
                SET IDENTITY_INSERT [dbo].[SportEvents] OFF;");

            this.databaseSportsContext.Database.ExecuteSqlCommand(
                @"SET IDENTITY_INSERT [dbo].[Results] ON;
                INSERT INTO [dbo].[Results] ([Id], [Score], [SportEvent_Id], [Team_Id])
                VALUES
                (1, 2, 1, 1),
                (2, 1, 2, 2),
                (3, 3, 4, 2),
                (4, 1, 1, 3),
                (5, 0, 3, 3),
                (6, 0, 3, 4),
                (7, 2, 4, 4),
                (8, 4, 2, 5),
                (9, 68, 5, 6),
                (10, 52, 6, 6),
                (11, 65, 5, 7),
                (12, 65, 7, 7),
                (13, 64, 7, 8),
                (14, 52, 6, 8);               
                SET IDENTITY_INSERT [dbo].[Results] OFF;");

            this.databaseSportsContext.SaveChanges();

            IUnitOfWork unit = new EFUnitOfWork(this.databaseSportsContext);

            TeamName tn1 = new TeamName {
                Name = "Шахтер Д"
            };
            TeamName tn2 = new TeamName {
                Name = "Динамо Бухарест"
            };
            TeamName tn3 = new TeamName {
                Name = "Динамо Киев"
            };
            TeamName tn4 = new TeamName {
                Name = "Сент-Этьен"
            };
            TeamName tn5 = new TeamName {
                Name = "Заря ЛГ"
            };
            TeamName tn6 = new TeamName {
                Name = "Манчестер Юнайтед"
            };
            TeamName tn7 = new TeamName {
                Name = "Манчестер С"
            };
            TeamName tn8 = new TeamName {
                Name = "Маккаби Т. А."
            };
            TeamName tn9 = new TeamName {
                Name = "Краснодар"
            };

            SportType sport = new SportType {
                Name = "Football"
            };

            Team t1 = new Team {
                Name = tn1.Name, Names = new List <TeamName> {
                    tn1
                }, SportType = sport
            };
            Team t2 = new Team {
                Name = tn2.Name, Names = new List <TeamName> {
                    tn2
                }, SportType = sport
            };
            Team t3 = new Team {
                Name = tn3.Name, Names = new List <TeamName> {
                    tn3
                }, SportType = sport
            };
            Team t4 = new Team {
                Name = tn4.Name, Names = new List <TeamName> {
                    tn4
                }, SportType = sport
            };
            Team t5 = new Team {
                Name = tn5.Name, Names = new List <TeamName> {
                    tn5
                }, SportType = sport
            };
            Team t6 = new Team {
                Name = tn6.Name, Names = new List <TeamName> {
                    tn6
                }, SportType = sport
            };
            Team t7 = new Team {
                Name = tn7.Name, Names = new List <TeamName> {
                    tn7
                }, SportType = sport
            };
            Team t8 = new Team {
                Name = tn8.Name, Names = new List <TeamName> {
                    tn8
                }, SportType = sport
            };
            Team t9 = new Team {
                Name = tn9.Name, Names = new List <TeamName> {
                    tn9
                }, SportType = sport
            };

            SportEvent event1 = new SportEvent {
                SportType = sport, Date = DateTime.Now
            };
            SportEvent event2 = new SportEvent {
                SportType = sport, Date = DateTime.Now
            };
            SportEvent event3 = new SportEvent {
                SportType = sport, Date = DateTime.Now
            };
            SportEvent event4 = new SportEvent {
                SportType = sport, Date = DateTime.Now
            };
            SportEvent event5 = new SportEvent {
                SportType = sport, Date = DateTime.Now
            };

            Result result1 = new Result {
                SportEvent = event1, Team = t1, IsHome = true, Score = 1
            };
            Result result2 = new Result {
                SportEvent = event1, Team = t2, IsHome = false, Score = 0
            };
            Result result3 = new Result {
                SportEvent = event2, Team = t3, IsHome = true, Score = 1
            };
            Result result4 = new Result {
                SportEvent = event2, Team = t4, IsHome = false, Score = 1
            };
            Result result5 = new Result {
                SportEvent = event3, Team = t5, IsHome = true, Score = 3
            };
            Result result6 = new Result {
                SportEvent = event3, Team = t6, IsHome = false, Score = 2
            };
            Result result7 = new Result {
                SportEvent = event4, Team = t7, IsHome = true, Score = 0
            };
            Result result8 = new Result {
                SportEvent = event4, Team = t8, IsHome = false, Score = 4
            };
            Result result9 = new Result {
                SportEvent = event5, Team = t9, IsHome = false, Score = 0
            };
            Result result10 = new Result {
                SportEvent = event5, Team = t1, IsHome = true, Score = 0
            };

            unit.GetRepository <Result>().Insert(result1);
            unit.GetRepository <Result>().Insert(result2);
            unit.GetRepository <Result>().Insert(result3);
            unit.GetRepository <Result>().Insert(result4);
            unit.GetRepository <Result>().Insert(result5);
            unit.GetRepository <Result>().Insert(result6);
            unit.GetRepository <Result>().Insert(result7);
            unit.GetRepository <Result>().Insert(result8);
            unit.GetRepository <Result>().Insert(result9);
            unit.GetRepository <Result>().Insert(result10);

            unit.SaveChanges();
        }
 public PlayerRepository(SportsContext context)
 {
     _sportsContext = context;
 }
Пример #27
0
 public SportsController(SportsContext context)
 {
     _context = context;
 }
Пример #28
0
 public PaymentService(SportsContext context) : base(context)
 {
 }
Пример #29
0
 public api_playersController(SportsContext context)
 {
     _context = context;
 }
Пример #30
0
        public void OneTimeInit()
        {
            this.databaseSportsContext = new SportsContext("SportsContext");

            // Clear tables
            this.databaseSportsContext.TeamNames.RemoveRange(
                this.databaseSportsContext.TeamNames);
            this.databaseSportsContext.Results.RemoveRange(
                this.databaseSportsContext.Results);
            this.databaseSportsContext.SportEvents.RemoveRange(
                this.databaseSportsContext.SportEvents);
            this.databaseSportsContext.Teams.RemoveRange(
                this.databaseSportsContext.Teams);
            this.databaseSportsContext.SportTypes.RemoveRange(
                this.databaseSportsContext.SportTypes);

            this.databaseSportsContext.SaveChanges();

            this.chartService = new ChartService(new EFUnitOfWork(this.databaseSportsContext));

            this.databaseSportsContext.Database.ExecuteSqlCommand(
                @"SET IDENTITY_INSERT [dbo].[SportTypes] ON;
                INSERT INTO [dbo].[SportTypes] ([Id], [Name])
                VALUES
                (1, 'Football');               
                SET IDENTITY_INSERT [dbo].[SportTypes] OFF;");

            this.databaseSportsContext.Database.ExecuteSqlCommand(
                @"SET IDENTITY_INSERT [dbo].[Teams] ON;
                INSERT INTO [dbo].[Teams] ([Id], [Name], [SportType_Id])
                VALUES
                (1, 'Manchester United', 1),
                (2, 'Milano', 1);               
                SET IDENTITY_INSERT [dbo].[Teams] OFF;");

            this.databaseSportsContext.Database.ExecuteSqlCommand(
                @"SET IDENTITY_INSERT [dbo].[TeamNames] ON;
                INSERT INTO [dbo].[TeamNames] ([Id], [Name], [Team_Id])
                VALUES
                (1, 'Manchester United', 1),
                (2, 'Milano', 2);               
                SET IDENTITY_INSERT [dbo].[TeamNames] OFF;");

            this.databaseSportsContext.Database.ExecuteSqlCommand(
                @"SET IDENTITY_INSERT [dbo].[SportEvents] ON;
                INSERT INTO [dbo].[SportEvents] ([Id], [Date], [SportType_Id])
                VALUES
                (1, '20161119 17:00', 1),
                (2, '20161120 17:00', 1),
                (3, '20161121 18:00', 1),
                (4, '20161122 16:00', 1),
                (5, '20161123 16:00', 1);
                SET IDENTITY_INSERT [dbo].[SportEvents] OFF;");

            this.databaseSportsContext.Database.ExecuteSqlCommand(
                @"SET IDENTITY_INSERT [dbo].[Results] ON;
                INSERT INTO [dbo].[Results] ([Id], [Score], [SportEvent_Id], [Team_Id])
                VALUES
                (1, 3, 1, 1),
                (2, 1, 1, 2),
                (3, 5, 2, 1),
                (4, 3, 2, 2),
                (5, 4, 3, 1),
                (6, 2, 3, 2),
                (7, 1, 4, 1),
                (8, 4, 4, 2),
                (9, 0, 5, 1),
                (10, 2, 5, 2);               
                SET IDENTITY_INSERT [dbo].[Results] OFF;");

            this.databaseSportsContext.SaveChanges();

            this.chartService = new ChartService(new EFUnitOfWork(this.databaseSportsContext));
        }