コード例 #1
0
 public async Task <List <TEntity> > GetAllAsync()
 {
     using (var db = new BPContext())
     {
         return(await db.Set <TEntity>().ToListAsync());
     }
 }
コード例 #2
0
 public async Task <TEntity> GetByIdAsync(int id)
 {
     using (var db = new BPContext())
     {
         return(await db.Set <TEntity>().FindAsync(id));
     }
 }
コード例 #3
0
ファイル: CategoryDal.cs プロジェクト: cmktass/Blog
 public async Task <List <Category> > GetAllCategoryWithPostCount()
 {
     using (var db = new BPContext())
     {
         return(await db.Categories.Include(i => i.PostCategories).ToListAsync());
     }
 }
コード例 #4
0
        async Task VerifyTask(BPContext context, bool sandbox)
        {
            var pairs = ParseIPN(context.RequestBody);
            var url   = sandbox ? $"https://test.bitpay.com/invoices/{pairs["invoice_id"]}" : $"https://bitpay.com/invoices/{pairs["invoice_id"]}";

            await ProcessVerificationResponse(JsonConvert.DeserializeObject <BPModel>(GetUrl(url)));
        }
コード例 #5
0
ファイル: CategoryDal.cs プロジェクト: cmktass/Blog
 public async Task <Category> GetCategoryByName(string name)
 {
     using (var db = new BPContext())
     {
         return(await db.Categories.Where(i => i.Name == name).FirstOrDefaultAsync());
     }
 }
コード例 #6
0
ファイル: UserDal.cs プロジェクト: cmktass/Blog
 public async Task <User> CheckUserAsync(User user)
 {
     using (var db = new BPContext())
     {
         return(await db.Users.Where(i => i.Email == user.Email && i.Password == user.Password).FirstOrDefaultAsync());
     }
 }
コード例 #7
0
ファイル: PostDal.cs プロジェクト: cmktass/Blog
 public async Task <List <Post> > GetAllPostWithCategories()
 {
     using (var db = new BPContext())
     {
         return(await db.Posts.Include(i => i.PostCategories).ThenInclude(i => i.Category).ToListAsync());
     }
 }
コード例 #8
0
 public async Task UpdateAsync(TEntity entity)
 {
     using (var db = new BPContext())
     {
         db.Set <TEntity>().Update(entity);
         await db.SaveChangesAsync();
     }
 }
コード例 #9
0
        public static async System.Threading.Tasks.Task ReCalculateAllTotalsAsync(BPContext context)
        {
            var scoring = context.ScoringSystem.AsNoTracking().ToArray();

            foreach (var p in context.Performances)
            {
                CalculateTotalPoints(p, scoring.FirstOrDefault(g => g.Position == p.Position));
            }
            var result = await context.SaveChangesAsync();
        }
コード例 #10
0
        public static void CalculateTotal(Performance p, BPContext context)
        {
            var scoring = context.ScoringSystem.Where(g => g.Position == p.Position)
                          .FirstOrDefault();
            var match = context.Matches.Where(m => m.ID == p.MatchID).SingleOrDefault();

            p.GoalsConceeded = match.GoalsConceeded;
            p.CleanSheet     = p.GoalsConceeded > 0 ? false : true;
            CalculateTotalPoints(p, scoring);
        }
コード例 #11
0
 public void MyTestMethod()
 {
     using (var context = new BPContext())
     {
         var accounts = context.Matches
                        .AsNoTracking()
                        .Include(g => g.Oposition)
                        .Include(g => g.Performances)
                        .ToList();
     }
 }
コード例 #12
0
        public void Test1()
        {
            var options = new DbContextOptionsBuilder <BPContext>()
                          .UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=BillericayPioneers;Trusted_Connection=True;MultipleActiveResultSets=true")
                          .Options;

            using (var context = new BPContext(options))
            {
                var players = context.Players.Include(g => g.Performances)
                              .ToArray();
            }
        }
コード例 #13
0
 public static bool IsValidUser(User user, BPContext context)
 {
     if (string.IsNullOrEmpty(user?.Username) || string.IsNullOrEmpty(user?.Password))
     {
         return(false);
     }
     else
     {
         return(context.Users.Any(g => g.Username == user.Username &&
                                  g.Password == ComputeHash(user.Password)));
     }
 }
コード例 #14
0
        public static async Task AddAsync(User user, BPContext context)
        {
            if (string.IsNullOrEmpty(user?.Username) || string.IsNullOrEmpty(user?.Password))
            {
                throw new Exception("Invalid username or password");
            }


            user.Password = ComputeHash(user.Password);
            await context.Users.AddAsync(user);

            context.SaveChanges();
        }
コード例 #15
0
 public void TogglePaid(int id)
 {
     using (var context = new BPContext())
     {
         var perf = context.Performances.FirstOrDefault(g => g.ID == id);
         if (perf != null)
         {
             perf.Paid = !perf.Paid;
             context.SaveChanges();
         }
         else
         {
             throw new System.Exception("Could not find performance");
         }
     }
 }
コード例 #16
0
        public PaymentViewModel()
        {
            using (var context = new BPContext())
            {
                var accounts = context.Matches
                               .AsNoTracking()
                               .Include(g => g.Oposition)
                               .Include(g => g.Performances).ThenInclude(g => g.Player)
                               .ToList();

                Matches = accounts;
                Players = context.Players.AsNoTracking()
                          .OrderBy(g => g.FirstName)
                          .ToArray();
            }
        }
コード例 #17
0
        async Task <IActionResult> ReceiveAsync()
        {
            BPContext context = new BPContext()
            {
                HttpRequest = Request
            };

            using (StreamReader reader = new StreamReader(context.HttpRequest.Body, Encoding.ASCII))
            {
                context.RequestBody = reader.ReadToEnd();
            }

            //Fire and forget verification task
            await Task.Run(() => VerifyTask(context, false));

            return(Ok());
        }
コード例 #18
0
        public async Task <IActionResult> Register(User user)
        {
            using (var context = new BPContext())
            {
                if (!ModelState.IsValid)
                {
                    return(View());
                }
                else if (context.Users.Any(g => g.Username == user.Username))
                {
                    ModelState.AddModelError("", "Username already exists");
                    return(View());
                }
                else
                {
                    await UserAuthentication.AddAsync(user, context);

                    return(View("Login"));
                }
            }
        }
コード例 #19
0
 public PlayersController(BPContext context)
 {
     _context = context;
 }
コード例 #20
0
 public HomeController(BPContext context)
 {
     _context = context;
 }
コード例 #21
0
 public static User GetUser(string username, string password, BPContext context)
 {
     return(context.Users.FirstOrDefault(g => g.Username == username &&
                                         g.Password == ComputeHash(password)));
 }
コード例 #22
0
ファイル: BPLibApi.cs プロジェクト: Ansersion/BcTool
 public static extern void BP_Init2Default(ref BPContext bp_context);
コード例 #23
0
ファイル: BPLibApi.cs プロジェクト: Ansersion/BcTool
 public static extern IntPtr BP_PackConnect(ref BPContext bp_context, IntPtr name, IntPtr password);
コード例 #24
0
ファイル: BPLibApi.cs プロジェクト: Ansersion/BcTool
 public static extern IntPtr BP_PackPing(ref BPContext bp_context);
コード例 #25
0
 public TeamsController(BPContext context)
 {
     _context = context;
 }
コード例 #26
0
ファイル: BPLibApi.cs プロジェクト: Ansersion/BcTool
 public static extern IntPtr BP_PackDisconn(ref BPContext bp_context);
コード例 #27
0
 public PerformancesController(BPContext context)
 {
     _context = context;
 }
コード例 #28
0
 public ScoringsController(BPContext context)
 {
     _context = context;
 }
コード例 #29
0
        public async Task <IActionResult> Login(LoginModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Invalid username/password");
                return(View());
            }
            var user = new User("", "", model.Username, model.Password);

            using (var context = new BPContext())
            {
                if (UserAuthentication.IsValidUser(user, context))
                {
                    var temp   = UserAuthentication.GetUser(user.Username, user.Password, context);
                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.Name, temp.FirstName),
                        new Claim("FullName", temp.ToString()),
                        new Claim(ClaimTypes.Role, temp.Access.ToString()),
                    };

                    var claimsIdentity = new ClaimsIdentity(
                        claims, CookieAuthenticationDefaults.AuthenticationScheme);

                    var authProperties = new AuthenticationProperties
                    {
                        //AllowRefresh = <bool>,
                        // Refreshing the authentication session should be allowed.

                        //ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(10),
                        // The time at which the authentication ticket expires. A
                        // value set here overrides the ExpireTimeSpan option of
                        // CookieAuthenticationOptions set with AddCookie.

                        //IsPersistent = true,
                        // Whether the authentication session is persisted across
                        // multiple requests. Required when setting the
                        // ExpireTimeSpan option of CookieAuthenticationOptions
                        // set with AddCookie. Also required when setting
                        // ExpiresUtc.

                        //IssuedUtc = <DateTimeOffset>,
                        // The time at which the authentication ticket was issued.

                        //RedirectUri = <string>
                        // The full path or absolute URI to be used as an http
                        // redirect response value.
                    };

                    await HttpContext.SignInAsync(
                        CookieAuthenticationDefaults.AuthenticationScheme,
                        new ClaimsPrincipal(claimsIdentity),
                        authProperties);

                    if (model.ReturnURL != null && Url.IsLocalUrl(model.ReturnURL))
                    {
                        return(Redirect(model.ReturnURL));
                    }
                    return(RedirectToAction("GetPlayerRankings", "Performances"));
                }
                else
                {
                    return(View("Login"));
                }
            }
        }
コード例 #30
0
 public DataBase(BPContext db)
 {
     _db = db;
 }