예제 #1
0
        // GET: api/Students
        public List <dynamic> GetAuditTrail()
        {
            //return db.Users;
            Tuks_Athletics_SystemEntities db = new Tuks_Athletics_SystemEntities();

            db.Configuration.ProxyCreationEnabled = false;
            return(getGetAuditTrailReturnList(db.AuditTrails.Include(xx => xx.User).ToList()));
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)

        {
            var identity = new ClaimsIdentity(context.Options.AuthenticationType);


            Tuks_Athletics_SystemEntities db = new Tuks_Athletics_SystemEntities();
            string UserName = context.UserName.ToLower().Trim('"');
            string Password = context.Password.Trim('"');;

            //var UserRole =
            Password = ComputeSha256Hash(Password);

            var userdata = db.Users.Where(u => u.Email.ToLower() == UserName && u.Password == Password).FirstOrDefault();

            if (userdata != null)
            {
                //dynamic toReturn = new ExpandoObject();
                //Role thisRole = db.Roles.Where(XX => XX.ID == userdata.Type_ID).FirstOrDefault();
                identity.AddClaim(new Claim(ClaimTypes.Role, userdata.Role.Name));
                identity.AddClaim(new System.Security.Claims.Claim(ClaimTypes.Email, userdata.Email));

                if (userdata.Role.Name == "Admin")
                {
                    identity.AddClaim(new System.Security.Claims.Claim(ClaimTypes.Role, "Admin"));
                }
                else
                {
                    identity.AddClaim(new System.Security.Claims.Claim(ClaimTypes.Role, "General"));
                }
                context.Validated(identity);
                //if(thisRole != null)
                //{
                //    toReturn.RoleName = thisRole.Name;
                //    returnFront( toReturn);
                //}
            }
            else
            {
                context.SetError("invalid_grant", "Provided username and password is incorrect");
                context.Rejected();
            }

            string ComputeSha256Hash(string RawData) // I prefer my data RAW, no salt for me please
            {
                using (SHA256 Sha256Hash = SHA256.Create())
                {
                    byte[] pBytes = Sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(RawData));

                    StringBuilder MyPassword = new StringBuilder();
                    for (int i = 0; i < RawData.Length; i++)
                    {
                        MyPassword.Append(pBytes[i].ToString("x2"));
                    }
                    return(MyPassword.ToString());
                }
            }
        }
예제 #3
0
        public string GetUserRole(string UserEmail)
        {
            Tuks_Athletics_SystemEntities db = new Tuks_Athletics_SystemEntities();

            db.Configuration.ProxyCreationEnabled = false;

            string UserRole = db.Users.Where(usr => usr.Email == UserEmail).FirstOrDefault().Type_ID.ToString();


            // var thisRole = db.Roles.Where(XX => XX.ID == zz.Type_ID).FirstOrDefault();
            //userdata.Type_ID = userdata.Type_ID;
            return(UserRole);
        }
        public IHttpActionResult PutPerformance(int id, PerformanceViewModel performance)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            //db.Entry(performance).State = EntityState.Modified;
            using (var ctx = new Tuks_Athletics_SystemEntities())
            {
                var existingPerformance = ctx.Performances.Where(s => s.Performance_ID == performance.Id).FirstOrDefault <Performance>();

                if (existingPerformance != null)
                {
                    existingPerformance.Result         = performance.Result;
                    existingPerformance.Date           = performance.Date;
                    existingPerformance.Athlete_ID     = performance.AthleteId;
                    existingPerformance.Heat_ID        = performance.HeatId;
                    existingPerformance.Event_ID       = performance.EventId;
                    existingPerformance.Medal_ID       = performance.MedalId;
                    existingPerformance.Age_ID         = performance.AgeId;
                    existingPerformance.Competition_ID = performance.CompetitionId;
                }

                try
                {
                    ctx.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PerformanceExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #5
0
        public IHttpActionResult PutAthlete(int id, AthleteViewModel athlete)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            //db.Entry(athlete).State = EntityState.Modified;
            using (var ctx = new Tuks_Athletics_SystemEntities())
            {
                var existingAthlete = ctx.Athletes.Where(s => s.Athlete_ID == athlete.Id).FirstOrDefault <Athlete>();

                if (existingAthlete != null)
                {
                    existingAthlete.Name        = athlete.Name;
                    existingAthlete.Surname     = athlete.Surname;
                    existingAthlete.Description = athlete.Description;
                    existingAthlete.Club_ID     = athlete.ClubId;
                    existingAthlete.Gender_ID   = athlete.GenderId;
                    existingAthlete.Status_ID   = athlete.StatusId;
                    existingAthlete.User_ID     = athlete.UserId;
                }

                try
                {
                    ctx.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AthleteExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #6
0
        public IHttpActionResult PutCompetition(int id, CompetitionViewModel competition)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            //db.Entry(competition).State = EntityState.Modified;
            using (var ctx = new Tuks_Athletics_SystemEntities())
            {
                var existingCompetition = ctx.Competitions.Where(s => s.Competition_ID == competition.Id).FirstOrDefault <Competition>();

                if (existingCompetition != null)
                {
                    existingCompetition.Name               = competition.Name;
                    existingCompetition.Venue_ID           = competition.VenueId;
                    existingCompetition.District_ID        = competition.DistrictId;
                    existingCompetition.Club_ID            = competition.ClubId;
                    existingCompetition.CompetitionType_ID = competition.CompetitionTypeId;
                    existingCompetition.Date               = competition.Date;
                }

                try
                {
                    ctx.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CompetitionExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #7
0
        public IHttpActionResult PutCoach(int id, Exercise excercise)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != excercise.Exercise_ID)
            {
                return(BadRequest());
            }

            // db.Entry(coach).State = EntityState.Modified;
            using (var ctx = new Tuks_Athletics_SystemEntities())
            {
                var curExcercise = ctx.Exercises.Where(s => s.Exercise_ID == excercise.Exercise_ID).FirstOrDefault();

                if (curExcercise != null)
                {
                    curExcercise.Exercise_ID = excercise.Exercise_ID;
                    curExcercise.Description = excercise.Description;
                    curExcercise.Sets        = excercise.Sets;
                    curExcercise.Reps        = excercise.Reps;
                    curExcercise.Cardio      = excercise.Cardio;
                    curExcercise.Strength    = excercise.Strength;
                    curExcercise.Name        = excercise.Name;
                }
                try

                {
                    ctx.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExerciseExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #8
0
        public IHttpActionResult PutUser(int id, UserVM user)

        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.User_ID)
            {
                return(BadRequest());
            }

            // db.Entry(coach).State = EntityState.Modified;
            using (var ctx = new Tuks_Athletics_SystemEntities())
            {
                var curCoach = ctx.Users.Where(zz => zz.Type_ID == user.Type_ID).FirstOrDefault();
                if (curCoach != null)
                {
                    curCoach.Name      = user.Name;
                    curCoach.Surname   = user.Surname;
                    curCoach.Email     = user.Email;
                    curCoach.Role.Name = ctx.Roles.Include(x => x.Users).Where(zz => db.Users.Any(xx => xx.Type_ID == zz.ID)).FirstOrDefault().Name;
                    curCoach.Type_ID   = user.Type_ID;
                }
                try

                {
                    ctx.SaveChanges();
                }

                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #9
0
        public IHttpActionResult PutClub(int id, ClubViewModel club)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            //db.Entry(club).State = EntityState.Modified;
            using (var ctx = new Tuks_Athletics_SystemEntities())
            {
                var existingClub = ctx.Clubs.Where(s => s.Club_ID == club.Id).FirstOrDefault <Club>();

                if (existingClub != null)
                {
                    existingClub.Name          = club.Name;
                    existingClub.Description   = club.Description;
                    existingClub.District_ID   = club.DistrictId;
                    existingClub.Federation_ID = club.FederationId;
                }

                try
                {
                    ctx.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClubExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #10
0
        public IHttpActionResult PutCoach(int id, Program program)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != program.Program_ID)
            {
                return(BadRequest());
            }

            // db.Entry(coach).State = EntityState.Modified;
            using (var ctx = new Tuks_Athletics_SystemEntities())
            {
                var curProgram = ctx.Programs.Where(s => s.Program_ID == program.Program_ID).FirstOrDefault();

                if (curProgram != null)
                {
                    curProgram.Program_ID  = program.Program_ID;
                    curProgram.Coach_ID    = program.Coach_ID;
                    curProgram.Name        = program.Name;
                    curProgram.Description = program.Description;
                }
                try

                {
                    ctx.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProgramExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #11
0
        public IHttpActionResult PutVenue(int id, VenueViewModel venue)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            //db.Entry(venue).State = EntityState.Modified;
            using (var ctx = new Tuks_Athletics_SystemEntities())
            {
                var existingVenue = ctx.Venues.Where(s => s.Venue_ID == venue.Id).FirstOrDefault <Venue>();

                if (existingVenue != null)
                {
                    existingVenue.Name        = venue.Name;
                    existingVenue.Capacity    = venue.Capacity;
                    existingVenue.District_ID = venue.District;
                }

                try
                {
                    ctx.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VenueExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #12
0
        public IHttpActionResult PutCoach(int id, CRUDviewmodel coach)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != coach.Coach_ID)
            {
                return(BadRequest());
            }

            // db.Entry(coach).State = EntityState.Modified;
            using (var ctx = new Tuks_Athletics_SystemEntities())
            {
                var curCoach = ctx.Coaches.Where(s => s.Coach_ID == coach.Coach_ID).FirstOrDefault();

                if (curCoach != null)
                {
                    curCoach.Name        = coach.Name;
                    curCoach.Surname     = coach.Surname;
                    curCoach.Email       = coach.Email;
                    curCoach.Description = coach.Description;
                }
                try

                {
                    ctx.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CoachExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #13
0
        public IHttpActionResult PutFederation(int id, FederationViewModel federation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            //db.Entry(federation).State = EntityState.Modified;
            using (var ctx = new Tuks_Athletics_SystemEntities())
            {
                var existingFederation = ctx.Federations.Where(s => s.Federation_ID == federation.Id).FirstOrDefault <Federation>();

                if (existingFederation != null)
                {
                    existingFederation.Name       = federation.Name;
                    existingFederation.Descrption = federation.Description;
                }

                try
                {
                    ctx.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FederationExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #14
0
        public IHttpActionResult PutDistrict(int id, DistrictViewModel district)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            //db.Entry(district).State = EntityState.Modified;
            using (var ctx = new Tuks_Athletics_SystemEntities())
            {
                var existingDistrict = ctx.Districts.Where(s => s.District_ID == district.Id).FirstOrDefault <District>();

                if (existingDistrict != null)
                {
                    existingDistrict.Name     = district.Name;
                    existingDistrict.Province = district.Province;
                }

                try
                {
                    ctx.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DistrictExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }