public async Task <Feedback> Submit([FromBody] FeedbackSubmission model)
        {
            AuthorizeAny(
                () => FeedbackService.UserIsEnrolled(model.GameId, Actor.Id).Result
                );

            await Validate(model);

            var result = await FeedbackService.Submit(model, Actor.Id);

            return(result);
        }
		public async static Task AddModifyFeedbackSubmission(FeedbackSubmission feedbackSubmission)
		{
		
			
				var db = DependencyService.Get<ISQLite> ().GetAsyncConnection ();
				await db.CreateTableAsync<FeedbackSubmission> ();
				if (feedbackSubmission.Id == 0) {
					await db.InsertAsync (feedbackSubmission);
				} else {
					await db.UpdateAsync (feedbackSubmission);
				}
			
		}
        public async Task <string> CreateFeedbackRecord(FeedbackSubmission feedback, string userId)
        {
            var query = $"INSERT INTO {SqlQueryTarget} (id, message, source, createdby, createdutc, status) VALUES(@Id, @Message, @Source, @CreatedBy, @CreatedUtc, @Status) RETURNING id";

            _connection.Open();
            return(await _connection.QuerySingleAsync <string>(query, new
            {
                Id = Guid.NewGuid(),
                feedback.Message,
                feedback.Source,
                CreatedBy = userId,
                CreatedUtc = DateTime.UtcNow,
                Status = FeedbackStatusEnum.UnAcknowledged
            }));
        }
		//private static readonly AsyncLock Mutex = new AsyncLock ();
		public async static Task<FeedbackSubmission> CreateFeedbackSubmission(int gymID, int profileID)
        {
			FeedbackSubmission feedbackSubmission = new FeedbackSubmission();
			feedbackSubmission.GymID = gymID;
			feedbackSubmission.ProfileID = profileID;
			feedbackSubmission.Date = DateTime.UtcNow;
		
			
				var db = DependencyService.Get<ISQLite> ().GetAsyncConnection ();
				await db.CreateTableAsync<FeedbackSubmission> ();
				await db.InsertAsync (feedbackSubmission);
			

            return feedbackSubmission;
        }
Exemple #5
0
        public async Task <Feedback> Submit(FeedbackSubmission model, string actorId)
        {
            var lookup = MakeFeedbackLookup(model.GameId, model.ChallengeId, model.ChallengeSpecId, actorId);
            var entity = await Store.Load(lookup);

            if (model.Submit) // Only fully validate questions on submit as a slight optimization
            {
                var valid = await FeedbackMatchesTemplate(model.Questions, model.GameId, model.ChallengeId);

                if (!valid)
                {
                    throw new InvalideFeedbackFormat();
                }
            }

            if (entity is Data.Feedback)
            {
                if (entity.Submitted)
                {
                    return(Mapper.Map <Feedback>(entity));
                }
                Mapper.Map(model, entity);
                entity.Timestamp = DateTimeOffset.UtcNow; // always last saved/submitted
                await Store.Update(entity);
            }
            else // create new entity and assign player based on user/game combination
            {
                var player = await Store.DbContext.Players.FirstOrDefaultAsync(s =>
                                                                               s.UserId == actorId &&
                                                                               s.GameId == model.GameId
                                                                               );

                if (player == null)
                {
                    throw new ResourceNotFound();
                }

                entity           = Mapper.Map <Data.Feedback>(model);
                entity.UserId    = actorId;
                entity.PlayerId  = player.Id;
                entity.Id        = Guid.NewGuid().ToString("n");
                entity.Timestamp = DateTimeOffset.UtcNow;
                await Store.Create(entity);
            }

            return(Mapper.Map <Feedback>(entity));
        }
        private async Task _validate(FeedbackSubmission model)
        {
            if ((await GameExists(model.GameId)).Equals(false)) // game must always exist
            {
                throw new ResourceNotFound();
            }

            if (model.ChallengeId.IsEmpty() != model.ChallengeSpecId.IsEmpty()) // must specify both or neither
            {
                throw new InvalideFeedbackFormat();
            }

            // if not blank, must exist for challenge and challenge spec
            if (model.ChallengeSpecId.NotEmpty() && (await SpecExists(model.ChallengeSpecId)).Equals(false))
            {
                throw new ResourceNotFound();
            }

            if (model.ChallengeId.NotEmpty() && (await ChallengeExists(model.ChallengeId)).Equals(false))
            {
                throw new ResourceNotFound();
            }

            // if specified, this is a challenge-specific feedback response, so validate challenge/spec/game match
            if (model.ChallengeSpecId.NotEmpty())
            {
                var game = await _store.DbContext.Games.FindAsync(model.GameId);

                var spec = await _store.DbContext.ChallengeSpecs.FindAsync(model.ChallengeSpecId);

                var challenge = await _store.DbContext.Challenges.FindAsync(model.ChallengeId);

                if (spec.GameId != game.Id)
                {
                    throw new ActionForbidden();
                }

                if (challenge.SpecId != spec.Id)
                {
                    throw new ActionForbidden();
                }
            }

            await Task.CompletedTask;
        }
 public async Task <ActionResult> PutFeedback(FeedbackSubmission feedback)
 {
     try
     {
         var userId = User.Claims.FirstOrDefault(c => c.Type == "sub")?.Value;
         _logger.LogInformation("Received a request to put feedback!", userId);
         return(Ok(new GenericDataResponseModel <string>
         {
             Success = true,
             Data = await _feedbackRepository.CreateFeedbackRecord(feedback, userId)
         }));
     }
     catch (Exception e)
     {
         // Todo: Add more identifiable information about this failure like userId or the token.
         _logger.LogError(e, $"Put feedback exception: {e.Message}.");
         return(Ok(new GenericResponseModel
         {
             Errors = e.Message
         }));
     }
 }
		public async Task AddModifyFeedbackSubmission(FeedbackSubmission feedbackSubmission)
		{
			await FeedbackSubmissionDAL.AddModifyFeedbackSubmission (feedbackSubmission);

		}
		public async static Task<FeedbackSubmission> GetFeedbackSubmissionByLocalID(int localFeedbackID)
		{
			FeedbackSubmission feedbackSubmission = new FeedbackSubmission();

			
				var db = DependencyService.Get<ISQLite> ().GetAsyncConnection ();
				await db.CreateTableAsync<FeedbackSubmission> ();
				feedbackSubmission = await db.GetAsync<FeedbackSubmission> (localFeedbackID);
			
			return feedbackSubmission;
		}