public ActionResult Details(int id)
        {
            var db = new FootballDbContext();

            var tactic = db.Footballs
                         .Include(t => t.Author)
                         .Where(t => t.Id == id)
                         .Select(t => new TacticsDetails
            {
                TacticName     = t.TacticName,
                Formation      = t.Formation,
                Description    = t.Description,
                Image          = t.Image,
                PlayerPosition = t.PlayerPosition,
                FullName       = t.Author.FullName,
                Id             = t.Id
            })
                         .FirstOrDefault();

            if (tactic == null)
            {
                return(HttpNotFound());
            }

            return(View(tactic));
        }
示例#2
0
 public static void Main(string[] args)
 {
     using (FootballDbContext db = new FootballDbContext())
     {
         SetDb(db);
     }
 }
        public ActionResult Create(CreateTactics model)
        {
            if (this.ModelState.IsValid)
            {
                var authorId = this.User.Identity.GetUserId();

                var tactic = new Football
                {
                    TacticName     = model.TacticName,
                    Description    = model.Description,
                    Formation      = model.Formation,
                    PlayerPosition = model.PlayerPosition,
                    Image          = model.Image,
                    AuthorId       = authorId
                };

                var db = new FootballDbContext();

                db.Footballs.Add(tactic);
                db.SaveChanges();

                return(RedirectToAction("Details", new { id = tactic.Id }));
            }

            return(View(model));
        }
示例#4
0
 public Repository(FootballDbContext db)
 {
     _db = db;
     if (_db != null)
     {
         _dbSet = _db.Set <T>();
     }
 }
示例#5
0
 public static IFootballManager MockFootballManager(FootballDbContext dbContext)
 {
     return(new FootballManager(
                MockFootballClient(),
                MockCompetitionRepository(dbContext),
                MockPlayerRepository(dbContext),
                MockTeamRepository(dbContext),
                new TracerLogManager()));
 }
示例#6
0
        public TestHome()
        {
            DbContextOptionsBuilder <FootballDbContext> builder = new DbContextOptionsBuilder <FootballDbContext>();

            builder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            DbContextOptions <FootballDbContext> options = builder.Options;

            _context = new FootballDbContext(options);
        }
示例#7
0
 public MockDbInitializer(
     FootballDbContext context,
     ILogger <MockDbInitializer> logger,
     IServiceProvider serviceProvider
     )
 {
     _context         = context;
     _logger          = logger;
     _serviceProvider = serviceProvider;
 }
示例#8
0
        public void CreateInMemoryDatabaseTest()
        {
            using (DbConnection connection = new SQLiteConnection("data source=:memory:"))
            {
                // This is important! Else the in memory database will not work.
                connection.Open();

                using (var context = new FootballDbContext(connection, false))
                {
                    context.Set <Team>().Add(new Team
                    {
                        Name  = "New",
                        Coach = new Coach
                        {
                            City      = "New",
                            FirstName = "New",
                            LastName  = "New",
                            Street    = "New"
                        },
                        Players = new List <Player>
                        {
                            new Player
                            {
                                City      = "New",
                                FirstName = "New",
                                LastName  = "New",
                                Street    = "New",
                                Number    = 1
                            },
                            new Player
                            {
                                City      = "New",
                                FirstName = "New",
                                LastName  = "New",
                                Street    = "New",
                                Number    = 2
                            }
                        },
                        Stadion = new Stadion
                        {
                            Name   = "New",
                            City   = "New",
                            Street = "New"
                        }
                    });

                    context.SaveChanges();
                }

                using (var context = new FootballDbContext(connection, false))
                {
                    Assert.AreEqual(1, context.Set <Team>().Count());
                }
            }
        }
示例#9
0
        public static FootballDbContext NewFootballDbContext(string databaseName = "testDB")
        {
            var options = new DbContextOptionsBuilder <FootballDbContext>()
                          .UseInMemoryDatabase(databaseName: databaseName)
                          .EnableSensitiveDataLogging()
                          .Options;


            var context = new FootballDbContext(options);

            return(context);
        }
示例#10
0
        public ActionResult Index()
        {
            var db = new FootballDbContext();

            var footballs = db.Footballs
                            .OrderByDescending(f => f.Id)
                            .Take(2)
                            .Select(f => new ListTactics
            {
                Id         = f.Id,
                TacticName = f.TacticName,
                Formation  = f.Formation,
                Image      = f.Image
            })
                            .ToList();

            return(View(footballs));
        }
        public ActionResult ConfirmDelete(int id)
        {
            var db = new FootballDbContext();

            var tactics = db.Footballs
                          .Where(t => t.Id == id)
                          .FirstOrDefault();

            if (tactics == null)
            {
                return(HttpNotFound());
            }

            db.Footballs.Remove(tactics);
            db.SaveChanges();

            return(RedirectToAction("All", "Football"));
        }
        public ActionResult Edit(CreateTactics models)
        {
            if (ModelState.IsValid)
            {
                using (var db = new FootballDbContext())
                {
                    var tactics = db.Footballs.Find(models.Id);

                    tactics.Description    = models.Description;
                    tactics.Formation      = models.Formation;
                    tactics.PlayerPosition = models.PlayerPosition;
                    tactics.TacticName     = models.TacticName;
                    tactics.Image          = models.Image;

                    db.SaveChanges();
                }
                return(RedirectToAction("TacticsDetails", new { id = models.Id }));
            }

            return(View(models));
        }
        public ActionResult All(int page = 1)
        {
            var db = new FootballDbContext();

            var pageSize = 5;

            var tactics = db.Footballs
                          .OrderByDescending(t => t.Id)
                          .Skip((page - 1) * pageSize)
                          .Select(t => new ListTactics
            {
                Id         = t.Id,
                Formation  = t.Formation,
                Image      = t.Image,
                TacticName = t.TacticName
            })
                          .ToList();

            ViewBag.CurrentPage = page;

            return(View(tactics));
        }
        public ActionResult Delete(int id)
        {
            var db = new FootballDbContext();

            var tactics = db.Footballs
                          .Where(t => t.Id == id)
                          .Select(t => new Delete
            {
                TacticName     = t.TacticName,
                Formation      = t.Formation,
                Description    = t.Description,
                Image          = t.Image,
                PlayerPosition = t.PlayerPosition,
                Id             = t.Id
            })
                          .FirstOrDefault();

            if (tactics == null)
            {
                return(HttpNotFound());
            }

            return(View(tactics));
        }
示例#15
0
 public PlayerRepository(FootballDbContext context) : base(context)
 {
     this.context = context;
 }
示例#16
0
 public AddAreasCommandHandler(FootballDbContext dbContext, IFootballDataHttpClient footballDataHttpClient)
 {
     _dbContext = dbContext;
     _footballDataHttpClient = footballDataHttpClient;
 }
 public AgentsController(FootballDbContext context)
 {
     _context = context;
 }
示例#18
0
 public FootballDBManager(FootballDbContext footballDbContext)
 {
     this.footballDbContext = footballDbContext;
 }
示例#19
0
 public PlayersService(FootballDbContext context)
 {
     _context = context;
 }
示例#20
0
 public EfPlayerRepository(FootballDbContext dbContext) : base(dbContext)
 {
 }
 public OwnersController(FootballDbContext context)
 {
     _context = context;
 }
 public ScoutsController(FootballDbContext context)
 {
     _context = context;
 }
 public CompetitionServiceTests()
 {
     this.context            = DatabaseTools.NewFootballDbContext(DB_NAME);
     this.competitionService = new CompetitionService(new UnitOfWork(this.context));
 }
示例#24
0
 public PlayerRepository(FootballDbContext context, IUserResolver userResolver) : base(context, userResolver)
 {
 }
示例#25
0
 public PositionsService(FootballDbContext context)
 {
     _context = context;
 }
示例#26
0
 public CompetitionTeamRepository(FootballDbContext context) : base(context)
 {
 }
示例#27
0
 public BaseEFRepository(FootballDbContext context, IUserResolver userResolver)
 {
     Context      = context;
     UserResolver = userResolver;
     DbSet        = Context.Set <T>();
 }
 public EntityFrameworkRepository(FootballDbContext dbContext)
 {
     DbContext = dbContext;
 }
 public FootballRepository(FootballDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public EfTeamRepository(FootballDbContext dbContext)
 {
     _dbContext = dbContext;
 }