コード例 #1
0
ファイル: HomeController.cs プロジェクト: vanpyrzericj/Alphon
        public IActionResult ProcessRegister(Account account)
        {
            if (!_context.Accounts.Any(x => x.email == account.email))
            {
                account.password      = Crypter.Blowfish.Crypt(account.password, Crypter.Blowfish.GenerateSalt());
                account.firstsemester = 2;
                account.lastlogin     = DateTime.MinValue;
                account.usertype      = "Student";
                _context.Accounts.Add(account);

                try
                {
                    _context.Enrollments.Add(new Enrollment
                    {
                        account   = account,
                        section   = _context.Sections.Find(24),
                        status    = 1,
                        dateadded = DateTime.Now
                    });
                    _context.Enrollments.Add(new Enrollment
                    {
                        account   = account,
                        section   = _context.Sections.Find(25),
                        status    = 1,
                        dateadded = DateTime.Now
                    });
                    _context.Enrollments.Add(new Enrollment
                    {
                        account   = account,
                        section   = _context.Sections.Find(28),
                        status    = 1,
                        dateadded = DateTime.Now
                    });
                    _context.Enrollments.Add(new Enrollment
                    {
                        account   = account,
                        section   = _context.Sections.Find(29),
                        status    = 1,
                        dateadded = DateTime.Now
                    });
                } catch (Exception ex)
                {
                    //This means the offering doesn't exist. They must not be using demo database. Ignore and continue.
                }


                _context.SaveChanges();

                return(View("~/Views/Home/RegisterResult.cshtml"));
            }
            else
            {
                return(View("~/Views/Home/RegisterResult.cshtml"));
            }
        }
コード例 #2
0
        public DrillHole AddDrillHole(DrillHole hole)
        {
            var newDrillHole = context.DrillHoles.Add(hole);

            context.SaveChanges();

            return(newDrillHole);
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: knjames/Alphon
 public IActionResult ProcessRegister(Account account)
 {
     if (!_context.Accounts.Any(x => x.email == account.email))
     {
         account.password      = Crypter.Blowfish.Crypt(account.password, Crypter.Blowfish.GenerateSalt());
         account.firstsemester = 1;
         account.lastlogin     = DateTime.MinValue;
         account.usertype      = "Student";
         _context.Accounts.Add(account);
         _context.SaveChanges();
         return(View("~/Views/Home/RegisterResult.cshtml"));
     }
     else
     {
         return(View("~/Views/Home/RegisterResult.cshtml"));
     }
 }
コード例 #4
0
        public IActionResult Create(Account account)
        {
            var salt = GenerateSalt();

            account.password = GenerateHashedPassword(account.password, salt);
            account.salt     = GetString(salt);
            _context.Accounts.Add(account);
            _context.SaveChanges();
            return(Redirect("/Admin/Students/" + account.Id));
        }
コード例 #5
0
        public void AddBan(BanAddModel model)
        {
            var ban = new Ban
            {
                BannedById     = model.BannedBy.Id,
                Cid            = model.Cid,
                Duration       = model.Duration.Minutes,
                ExpirationTime = DateTime.Now + model.Duration,
                Server         = model.Server,
                Reason         = model.BanReason,
                TargetId       = model.BanTarget.Id,
                Ip             = model.Ip,
                Time           = DateTime.Now,
                Unbanned       = false,
                Type           = model.Permaban ? BanType.Permaban : BanType.Tempban
            };

            _db.Bans.Add(ban);
            _db.SaveChanges();
        }
コード例 #6
0
        public IActionResult ClearNotification(int notificationId)
        {
            var identity = (ClaimsIdentity)User.Identity;
            IEnumerable <Claim> claims = identity.Claims;
            var val = claims.First(x => x.Type == "sub");

            var notification = _context.Notifications.Where(x => x.Id == notificationId).Include(a => a.account).First();

            //Ensure The Authenticated User Is Doing the Clearing
            if (Convert.ToInt32(val.Value) != notification.account.Id)
            {
                return(Unauthorized());
            }
            notification.status = 1;
            _context.SaveChanges();
            return(Ok());
        }
コード例 #7
0
        public JsonResult AddToCart(int SemesterID, int courseId, int sectionForRecitationId)
        {
            var identity = (ClaimsIdentity)User.Identity;
            IEnumerable <Claim> claims = identity.Claims;
            var val = claims.First(x => x.Type == "sub");

            var account = _context.Accounts.Find(Convert.ToInt32(val.Value));

            var courseEnrollment = new Enrollment
            {
                account   = account,
                section   = _context.Sections.First(x => x.offering.Id == courseId),
                status    = 2,
                dateadded = DateTime.Now
            };

            Enrollment recitationEnrollment = null;

            if (sectionForRecitationId != 0)
            {
                recitationEnrollment = new Enrollment
                {
                    account   = account,
                    section   = _context.Sections.Find(sectionForRecitationId),
                    status    = 2,
                    dateadded = DateTime.Now
                };
            }


            if (CheckCart(SemesterID, account, courseEnrollment.section.Id, sectionForRecitationId))
            {
                _context.Enrollments.Add(courseEnrollment);
                if (sectionForRecitationId != 0)
                {
                    _context.Enrollments.Add(recitationEnrollment ?? throw new InvalidOperationException());
                }
                _context.SaveChanges();
            }

            else
            {
                return(new JsonResult(new { status = "false" }));
            }

            return(new JsonResult(new { status = "success" }));
        }
コード例 #8
0
        private static (Player admin, Player banTarget) PrepareDatabase(HubContext context)
        {
            var admin = new Player()
            {
                ByondVersion = "511",
                Cid          = "112315121",
                Ckey         = "bo20202",
                Country      = "Russia",
                FirstSeen    = DateTime.Now - TimeSpan.FromDays(15),
                Flags        = 11,
                Ip           = "127.0.0.1",
                LastSeen     = DateTime.Now,
                Rank         = "Admin",
                Registered   = DateTime.Now - TimeSpan.FromDays(150)
            };
            var banTarget = new Player()
            {
                ByondVersion = "511",
                Cid          = "124125121",
                Ckey         = "jshepard",
                Country      = "Russia",
                FirstSeen    = DateTime.Now - TimeSpan.FromMinutes(15),
                Flags        = 0,
                Ip           = "127.0.0.2",
                LastSeen     = DateTime.Now,
                Rank         = "Player",
                Registered   = DateTime.Now - TimeSpan.FromMinutes(15)
            };

            context.Players.Add(admin);
            context.Players.Add(banTarget);
            context.SaveChanges();


            return(admin, banTarget);
        }