public IActionResult IsDailyChallengeCompleted(CheckDailyChallengeDTO checkDaily) { if (checkDaily == null) { return(BadRequest()); } User usr = _userRepo.GetById(checkDaily.UserID); if (usr == null) { return(BadRequest()); } ChallengeUser challenge = _challengeRepo.GetUserChallenge(checkDaily.UserID, checkDaily.ChallengeID); if (challenge == null) { return(BadRequest()); } if (challenge.CompletedDate != null) { return(StatusCode(304)); } //Timestamp, DO NOT CHANGE VALUE! Needed to check the daily completed challenges. DateTime timeStamp = _challengeRepo.GetTimeStamp(); if (_challengeRepo.UserHasCompletedDailyChallengeOfCategory(checkDaily.UserID, challenge.Challenge.Category.CategoryId, timeStamp.Day, timeStamp.Month, timeStamp.Year)) { return(StatusCode(303)); } return(Ok(new CheckDailyChallengeResponseDTO(timeStamp))); }
public IActionResult GetUserChallenges(int id) { User user = _userRepo.GetById(id); if (user == null) { return(BadRequest()); } return(Ok(_challengeRepo.GetUserChallenges(id).Select(c => ChallengeUser.MapToUserChallengeDTO(c)).ToList())); }
private IEnumerable <Claim> GetClaims(ChallengeUser userApp, List <String> audiences) { //email payloading to inside of jwt var userList = new List <Claim> { //new Claim(ClaimTypes.NameIdentifier,userApp.Id), new Claim(JwtRegisteredClaimNames.Email, userApp.Email), new Claim(ClaimTypes.Name, userApp.UserName), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) }; userList.AddRange(audiences.Select(x => new Claim(JwtRegisteredClaimNames.Aud, x))); return(userList); }
public IActionResult CompleteChallenge(CompleteChallengeDTO complete) { if (complete == null || complete.Feedback == null || complete.CompletedOn == null) { return(BadRequest()); } User usr = _userRepo.GetById(complete.UserID); if (usr == null) { return(BadRequest()); } ChallengeUser challenge = _challengeRepo.GetUserChallenge(complete.UserID, complete.ChallengeID); if (challenge == null) { return(BadRequest()); } if (challenge.CompletedDate != null) { return(StatusCode(304)); } if (_challengeRepo.UserHasCompletedDailyChallengeOfCategory(complete.UserID, challenge.Challenge.Category.CategoryId, complete.CompletedOn.Day, complete.CompletedOn.Month, complete.CompletedOn.Year)) { return(StatusCode(303)); } try { challenge.Feedback = complete.Feedback; challenge.Rating = complete.Rating; _userRepo.AddExp(usr); _userRepo.SaveChanges(); _challengeRepo.CompleteChallenge(challenge, complete.CompletedOn); _userRepo.RaiseLeaderboardScore(complete.UserID); _userRepo.SaveChanges(); _challengeRepo.SaveChanges(); } catch (Exception) { return(StatusCode(500)); } return(Ok(new CompleteChallengeDateDTO() { CompletedDate = challenge.CompletedDate.Value })); }
public async Task <UserDto> CreateUserAsync(RegisterDto createUserDto) { var user = new ChallengeUser { Id = Convert.ToBase64String(Encoding.UTF8.GetBytes(createUserDto.UserName)), Name = createUserDto.Name, LastName = createUserDto.LastName, Email = createUserDto.Email, UserName = createUserDto.UserName }; var result = await _userManager.CreateAsync(user, createUserDto.Password); if (!result.Succeeded) { var errors = result.Errors.Select(x => x.Description).ToList(); return(new UserDto()); } return(ObjectMapper.Mapper.Map <UserDto>(user)); }
public async Task <ActionResult <ChallengeUser> > PostChallengeUser([FromBody] ChallengeUser challengeUser) { _context.ChallengeUser.Add(challengeUser); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { throw; } return(CreatedAtAction("GetUserChallenge", new { userId = challengeUser.UserId, challengeId = challengeUser.ChallengeId, executionId = challengeUser.ExecutionId, finishHour = challengeUser.FinishHour })); }
public LoginResponse CreateToken(ChallengeUser userApp) { var accessTokenExpriation = DateTime.Now.AddMinutes(_tokenOption.AccessTokenExpiration); var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_tokenOption.SecurityKey)); SigningCredentials signingCredentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature); JwtSecurityToken jwtSecurityToken = new JwtSecurityToken( issuer: _tokenOption.Issuer, expires: accessTokenExpriation, notBefore: DateTime.Now, claims: GetClaims(userApp, _tokenOption.Audience), signingCredentials: signingCredentials ); var handler = new JwtSecurityTokenHandler(); var token = handler.WriteToken(jwtSecurityToken); var tokenDto = new LoginResponse { AccessTokenExpiration = accessTokenExpriation, AccessToken = token, }; return(tokenDto); }
public IActionResult GetUserWithChallenges(int id) { User user = _userRepo.GetById(id); if (user == null) { return(NotFound()); } List <ChallengesOfUserDTO> challenges = _challengeRepo.GetUserChallenges(id).Select(c => ChallengeUser.MapToChallengesOfUserDTO(c)).ToList(); return(Ok(Model.User.MapUserToUserWithChallengesDTO(user, challenges, _userRepo.GetUserCategories(user.UserId).ToList()))); }
public void CompleteChallenge(ChallengeUser challenge, DateTime date) { challenge.CompletedDate = date; }
public User() { _interestsVector = new double[36]; Food = new Food <Triple>() { Burger = new Triple(), Pizza = new Triple(), Sushi = new Triple(), Snacks = new Triple(), Vegan = new Triple(), Kosher = new Triple() }; Drinks = new Drinks <Triple>() { Beer = new Triple(), Wine = new Triple(), Cocktail = new Triple(), BeveragePackages = new Triple(), Jin = new Triple(), Whiskey = new Triple(), WideRangeOfBeverages = new Triple() }; Atmosphere = new Atmosphere <Triple>() { Irish = new Triple(), Chill = new Triple(), Dance = new Triple(), Sport = new Triple(), Shisha = new Triple(), Party = new Triple() }; Company = new Company <Triple>() { Dating = new Triple(), Friends = new Triple(), KidsFriendly = new Triple(), PetsFriendly = new Triple(), Colleagues = new Triple() }; Music = new Music <Triple>() { Pop = new Triple(), Jazz = new Triple(), Mizrahit = new Triple(), Greek = new Triple(), Trance = new Triple(), Mainstream = new Triple(), Israeli = new Triple(), LiveMusic = new Triple(), Reggaeton = new Triple(), OpenMic = new Triple(), StandUp = new Triple() }; SmokingFree = new Triple(); ChallengeUser = new ChallengeUser(); }
public async Task InitializeData() { _dbContext.Database.EnsureDeleted(); if (_dbContext.Database.EnsureCreated()) { await CreateRoles(); //Multimeduser await CreateUser("SofieV", "*****@*****.**", "P@ssword123", UserRole.MULTIMED); //categories Category c = new Category() { Name = "Ondergewicht" }; _dbContext.Add(c); //challenges Challenge ch = new Challenge() { ChallengeImage = "", Description = "Loop 2 km", Title = "Lopen", Category = c, Level = 1 }; //TherapistType TherapistType thType = new TherapistType() { Type = "Diëtist", Categories = new List <Category> { c } }; _dbContext.Add(thType); //OpeningTimes List <OpeningTimes> otList = new List <OpeningTimes>() { new OpeningTimes() { Interval = "9-17" }, new OpeningTimes() { Interval = "9-17" }, new OpeningTimes() { Interval = "9-17" }, new OpeningTimes() { Interval = "9-17" }, new OpeningTimes() { Interval = "9-17" }, new OpeningTimes() { Interval = "9-17" }, new OpeningTimes() { Interval = "9-17" }, }; //Therapist Therapist th = new Therapist() { FirstName = "Therapist", LastName = "De Peape", HouseNumber = 1, PhoneNumber = "0474139526", PostalCode = 9000, Street = "test", Website = "www.google.com", City = "Gent", Email = "*****@*****.**", TherapistType = thType, OpeningTimes = otList }; await CreateUser("TestTh", th.Email, "P@ssword123", UserRole.THERAPIST); _dbContext.Add(th); //company Company cmp = new Company() { Name = "Multimed", Street = "Multimedstraat", City = "Gent", Contract = DateTime.Now.AddYears(30), Country = "Belgie", Mail = "*****@*****.**", Phone = "04785889764", PostalCode = 9000, HouseNumber = 1, Site = "multimed.be" }; _dbContext.Add(cmp); //user User usr = new User() { FirstName = "Boefer", FamilyName = "rob", Phone = "0478995888", ExperiencePoints = 16, Company = cmp, Email = "*****@*****.**", Contract = cmp.Contract }; usr.AddTherapist(th); //many to many from user List <CategoryUser> cusr = new List <CategoryUser> { new CategoryUser() { Category = c, User = usr, UserId = usr.UserId, CategoryId = c.CategoryId } }; ChallengeUser chUsr = new ChallengeUser() { ChallengeUserId = usr.UserId, User = usr, ChallengeId = ch.ChallengeId, Challenge = ch }; usr.AddChallenges(new List <ChallengeUser> { chUsr }); usr.AddCategories(cusr); //account user await CreateUser("Boeferrob", usr.Email, "P@ssword123", UserRole.USER); _dbContext.Add(usr); _dbContext.ChallengeUser.Add(chUsr); th.AddClient(usr); #region Save changes _dbContext.SaveChanges(); #endregion } }
//Init used data public DummyProject3_BackendContext() { // Create objects Category category1 = new Category { CategoryId = 0, Name = "Afvallen" }; Challenge challenge1 = new Challenge { ChallengeId = 0, ChallengeImage = "Image url", Description = "Loop 1500 meter", Title = "First run" }; Challenge challenge2 = new Challenge { ChallengeId = 1, ChallengeImage = "Image url", Description = "Loop 2000 meter", Title = "Second run" }; Company company1 = new Company { CompanyId = 0, City = "Wetteren", Contract = new DateTime(2020, 05, 15), Country = "België", HouseNumber = 3, Mail = "*****@*****.**", Name = "Xenox", Phone = "0474139526", PostalCode = 9230, Site = "www.google.com", Street = "Kalkensteenweg" }; User user1 = new User { UserId = 0, Phone = "0473139526", Contract = new DateTime(2020, 05, 15), Email = "*****@*****.**", ExperiencePoints = 0, FamilyName = "Grillaert", FirstName = "Ruben" }; User user2 = new User { UserId = 1, Phone = "0412345678", Contract = new DateTime(2020, 05, 15), Email = "*****@*****.**", ExperiencePoints = 0, FamilyName = "Boel", FirstName = "Arno" }; Therapist therapist1 = new Therapist { TherapistId = 0, City = "stad", Email = "*****@*****.**", FirstName = "Thor", HouseNumber = 2, LastName = "Krets", PhoneNumber = "093661686", PostalCode = 9000, Street = "straat", Website = "www.test.be" }; OpeningTimes openingTimes1 = new OpeningTimes { OpeningTimesId = 0, Interval = "09:00 - 18:30" }; OpeningTimes openingTimes2 = new OpeningTimes { OpeningTimesId = 1, Interval = "09:00 - 18:30" }; TherapistType therapistType1 = new TherapistType { TherapistTypeId = 0, Type = "therapisttype", }; // Create many to many objects ChallengeUser challengeUser1 = new ChallengeUser { Challenge = challenge1, ChallengeId = challenge1.ChallengeId, ChallengeUserId = 0, User = user1, UserId = user1.UserId }; ChallengeUser challengeUser2 = new ChallengeUser { Challenge = challenge2, ChallengeId = challenge2.ChallengeId, ChallengeUserId = 1, User = user1, UserId = user1.UserId }; TherapistUser therapistUser1 = new TherapistUser { TherapistUserId = 0, Therapist = therapist1, TherapistId = therapist1.TherapistId, User = user1, UserId = user1.UserId }; TherapistUser therapistUser2 = new TherapistUser { TherapistUserId = 1, Therapist = therapist1, TherapistId = therapist1.TherapistId, User = user2, UserId = user2.UserId }; // Set connections between objects challenge1.Category = category1; challenge2.Category = category1; company1.CompanyMembers = new List <User>() { user1, user2 }; therapist1.OpeningTimes = new List <OpeningTimes>() { openingTimes1 }; therapist1.TherapistType = therapistType1; therapistType1.Categories = new List <Category>() { category1 }; user1.Categories = new List <CategoryUser>() { new CategoryUser() { CategoryId = category1.CategoryId, Category = category1, User = user1, UserId = user1.UserId } }; user2.Categories = new List <CategoryUser>() { new CategoryUser() { CategoryId = category1.CategoryId, Category = category1, User = user2, UserId = user2.UserId } }; user1.Challenges = new List <ChallengeUser>() { challengeUser1, challengeUser2 }; user2.Challenges = new List <ChallengeUser>(); user1.Company = company1; user2.Company = company1; user1.Therapists = new List <TherapistUser>() { therapistUser1 }; user2.Therapists = new List <TherapistUser>() { therapistUser2 }; // Init properties Category = category1; Categories = new[] { category1 }; Companies = new[] { company1 }; Challenges = new[] { challenge1, challenge2 }; Therapists = new[] { therapist1 }; Users = new[] { user1, user2 }; ChallengesUser = new[] { challengeUser1, challengeUser2 }; TherapistTypes = new[] { therapistType1 }; OpeningTimes = new[] { openingTimes1, openingTimes2, openingTimes2, openingTimes2, openingTimes2, openingTimes2, openingTimes2 }; // Create DTO's AddUserDTO = new AddUserDTO { Categories = new List <int>() { 1 }, Company = 1, Email = "*****@*****.**", FamilyName = "test", FirstName = "test", Phone = "0471236548", Therapists = new List <int>() { 1 } }; EditUserDTO = new EditUserDTO { Categories = new List <int>() { 1 }, Email = "*****@*****.**", FamilyName = "test", FirstName = "test", Phone = "0471236548", UserId = 1, Contract = new DateTime() }; AddTherapistDTO = new AddTherapistDTO { City = "test", Email = "test", FirstName = "test", HouseNumber = 1, LastName = "test", PhoneNumber = "test", PostalCode = 9000, Street = "test", TherapistTypeId = 0, Website = "test" }; AddTherapistTypeDTO = new AddTherapistTypeDTO { Categories = new List <int>() { 1 }, Type = "test" }; EditTherapistDTO = new EditTherapistDTO { City = "test", Email = "test", FirstName = "test", HouseNumber = 1, LastName = "test", PhoneNumber = "test", PostalCode = 5000, Street = "test", TherapistId = 0, Website = "test", TherapistTypeId = 0, OpeningTimes = new List <OpeningTimes>() { new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 }, new OpeningTimes() { Interval = "9-19", OpeningTimesId = 0 } } }; EditTherapistTypeDTO = new EditTherapistTypeDTO { Id = 0, Categories = new List <int>() { 0 }, Type = "therapisttype" }; AddCompanyDTO = new AddCompanyDTO { City = "test", Contract = new DateTime(), Country = "test", HouseNumber = 3, Mail = "test", Name = "test", Phone = "test", PostalCode = 9000, Site = "test", Street = "test" }; EditCompanyDTO = new EditCompanyDTO { City = "test", Contract = new DateTime(), Country = "test", HouseNumber = 3, Mail = "test", Name = "test", Phone = "test", PostalCode = 9000, Site = "test", Street = "test", CompanyId = 0, CompanyMembers = new List <User>() { user1, user2 } }; AddChallengeDTO = new AddChallengeDTO { CategoryId = 0, ChallengeImage = "test", Description = "test", Title = "test" }; CompleteChallengeDTO = new CompleteChallengeDTO { ChallengeID = 0, UserID = 0, Rating = 3, Feedback = "test", CompletedOn = CompleteChallengeDate }; ChallengesUserDTO = new ChallengesUserDTO { ChallengeIds = new List <int>() { 0 }, UserId = 0 }; EditAppUserDTO = new EditAppUserDTO { UserId = 1, Email = "*****@*****.**", FamilyName = "test", FirstName = "tests", Phone = "0474139526" }; //UserManager IdentityUser = new IdentityUser(); }