public ActionResult <QuestDto> CreateQuest(QuestForCreationDto quest) { //if(quest.Name==quest.Description) //{ // ModelState.AddModelError("Description", // "Description must be different from Name."); //} if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var questEntity = _mapper.Map <Entities.Quest>(quest); var user = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value; var userEntity = _croudSeekRepository.GetUsers().Where((u) => u.Name == user).FirstOrDefault(); if (userEntity != null) { questEntity.OwnerId = userEntity.Id; } _croudSeekRepository.AddQuest(questEntity); _croudSeekRepository.Save(); var questToReturn = _mapper.Map <QuestDto>(questEntity); questToReturn.CanEdit = true; questToReturn.IsOwner = true; return(CreatedAtRoute("GetQuest", new { questId = questToReturn.Id }, questToReturn)); }
public ActionResult <ViewDto> CreateViewForQuest(int questId, ViewForCreationDto view) { if (!_croudSeekRepository.QuestExists(questId)) { return(NotFound()); } if (view == null) { return(NotFound()); } if (view.UserWeights != null && view.UserWeights.Select((w) => w.UserId).Distinct().Count() != view.UserWeights.Count ) { ModelState.AddModelError("UserWeights", "There can only be one UserWeight per User."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var viewEntity = _mapper.Map <Entities.View>(view); _croudSeekRepository.AddViewByQuest(questId, viewEntity); _croudSeekRepository.Save(); var viewToReturn = _mapper.Map <ViewDto>(viewEntity); return(CreatedAtRoute("GetView", new { questId = questId, viewId = viewToReturn.Id }, viewToReturn)); }
public ActionResult <UserDto> CreateUser(UserForCreationDto user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userEntity = _mapper.Map <Entities.User>(user); _croudSeekRepository.AddUser(userEntity); _croudSeekRepository.Save(); var userToReturn = _mapper.Map <UserDto>(userEntity); return(CreatedAtRoute("GetUser", new { userId = userToReturn.Id }, userToReturn)); }
//[Authorize(Policy = CroudSeek.Shared.Policies.CanManageQuests)] //[Authorize] public ActionResult <DataPointDto> CreateDataPointForQuest( int questId, DataPointForCreationDto dataPoint) { if (!_croudSeekRepository.QuestExists(questId)) { return(NotFound()); } var dataPointEntity = _mapper.Map <Entities.DataPoint>(dataPoint); dataPointEntity.QuestId = questId; var userName = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value; var user = _croudSeekRepository.GetUsers().Where((u) => u.Name == userName).FirstOrDefault(); //TODO - Allow Quest to be created without user name through email verification if (user == null) { return(ValidationProblem($"Invalid user: {userName}")); } dataPointEntity.OwnerId = user.Id; _croudSeekRepository.AddDataPoint(questId, dataPointEntity); _croudSeekRepository.Save(); var dataPointToReturn = _mapper.Map <DataPointDto>(dataPointEntity); return(CreatedAtRoute("GetDataPointForQuest", new { questId = questId, dataPointId = dataPointToReturn.Id }, dataPointToReturn)); }
public IActionResult GetApplicationUserProfile(string subject) { var applicationUserProfileFromRepo = _croudSeekRepository .GetApplicationUserProfile(subject); if (applicationUserProfileFromRepo == null) { // subject must come from token var subjectFromToken = User.Claims.FirstOrDefault(c => c.Type == "sub").Value; applicationUserProfileFromRepo = new Entities.ApplicationUserProfile() { Subject = subject, SubscriptionLevel = "FreeUser" }; _croudSeekRepository.AddApplicationUserProfile(applicationUserProfileFromRepo); _croudSeekRepository.Save(); } return(Ok(_mapper.Map <CroudSeek.Shared.ApplicationUserProfile>(applicationUserProfileFromRepo))); }
public ActionResult <ZoneDto> CreateZone(ZoneForCreationDto zone) { if (zone.Name == zone.Description) { ModelState.AddModelError("Description", "Description must be different from Name."); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var zoneEntity = _mapper.Map <Entities.Zone>(zone); _croudSeekRepository.AddZone(zoneEntity); _croudSeekRepository.Save(); var zoneToReturn = _mapper.Map <ZoneDto>(zoneEntity); return(CreatedAtRoute("GetZone", new { zoneId = zoneToReturn.Id }, zoneToReturn)); }
public ActionResult <UserWeightDto> CreateUserWeight(UserWeightForCreationDto userWeight) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userFromRepo = _croudSeekRepository.GetUser(userWeight.UserId); if (userFromRepo == null) { return(NotFound()); } var userWeightEntity = _mapper.Map <Entities.UserWeight>(userWeight); _croudSeekRepository.AddUserWeight(userWeightEntity); _croudSeekRepository.Save(); var userWeightToReturn = _mapper.Map <UserWeightDto>(userWeightEntity); return(CreatedAtRoute("GetUserWeight", new { userWeightId = userWeightToReturn.Id }, userWeightToReturn)); }
public async Task <ActionResult <RegistrationResponse> > RegisterAsync(RegistrationRequest request) { var response = await _authenticationService.RegisterAsync(request); var user = new User() { Name = request.UserName, Email = request.Email, }; _croudSeekRepository.AddUser(user); if (_croudSeekRepository.Save()) { return(Ok(response)); } throw new System.Exception($"Unable to register."); }