public async Task <ActionResult <TSFeedback> > GetFeedback()
        {
            string userID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(userID, "Requested Feedback", MethodBase.GetCurrentMethod());

            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV
            {
                Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5),
                IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10)
            };


            if (!string.IsNullOrEmpty(ClientSymmKeyAndIV.Key))
            {
                TSFeedbackEntity feedbackEntity = await TS.FindFeedback(userID, true, string.Empty);


                if (feedbackEntity != null)
                {
                    TSFeedback result = feedbackEntity.toTSFeedback();

                    GlobalFunctions.CmdEncryptEntitySymm(result, ClientSymmKeyAndIV);

                    return(result);
                }
                else
                {
                    return(new TSFeedback());
                }
            }
            else
            {
                return(new TSFeedback());
            }
        }
Esempio n. 2
0
        public static async Task CmdAddOrUpdateFeedback(TSFeedback ParTSFeedback)
        {
            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalData.CurrJWT);

            GlobalFunctions.CmdTrimEntity(ParTSFeedback);

            TSFeedback tsFeedbackForSend = GlobalFunctions.CopyObject <TSFeedback>(ParTSFeedback);


            LocalData.currFeedback = await httpClient.MyPostJsonGetJsonAsync("feedback/Add", tsFeedbackForSend);


            if (string.IsNullOrEmpty(LocalData.currFeedback.Text))
            {
                LocalData.oldFeedbackText = string.Empty;
            }
            else
            {
                LocalData.oldFeedbackText = LocalData.currFeedback.Text.ToLower();
            }

            httpClient.DefaultRequestHeaders.Accept.Clear();
        }
 public CosmosDocFeedback(TSFeedback tsFeedback)
 {
     UserID  = tsFeedback.UserID;
     ID      = tsFeedback.ID;
     Text    = tsFeedback.Text;
     AddDate = tsFeedback.AddDate;
     DocType = (int)DocTypeEnum.Feedback;
     GeneratePK();
 }
Esempio n. 4
0
        public async Task <ActionResult <TSFeedback> > Add(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "feedback/add")] HttpRequest req,
            ILogger log)
        {
            List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum>
            {
                WebApiUserTypesEnum.Authorized,
                WebApiUserTypesEnum.Admin
            };

            ClaimsPrincipal User = MyTokenValidator.Authenticate(req, localAllowedRoles, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            TSFeedback tsFeedback = await MyFromBody <TSFeedback> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));



            tsFeedback.UserID = Guid.Parse(LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));
            await CosmosAPI.cosmosDBClientActivity.AddActivityLog(tsFeedback.UserID, "Add or update Feedback", TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            string userName = LocalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            if (!tsFeedback.UserID.Equals(Guid.Empty))
            {
                if (userName.Equals("demouser"))
                {
                    return(new TSFeedback());
                }
            }

            CosmosDocFeedback oldFeedback = await CosmosAPI.cosmosDBClientFeedback.FindFeedback(tsFeedback.UserID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            if (oldFeedback is null)
            {
                tsFeedback.ID      = Guid.NewGuid();
                tsFeedback.AddDate = DateTime.UtcNow;
                bool b = await CosmosAPI.cosmosDBClientFeedback.AddFeedback(tsFeedback, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

                if (b)
                {
                    await CosmosAPI.cosmosDBClientSetting.UpdateSettingCounter(Guid.Empty, "FeedbackCount", true, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));
                }
            }
            else
            {
                if (oldFeedback.Text != tsFeedback.Text)
                {
                    await CosmosAPI.cosmosDBClientFeedback.UpdateFeedback(tsFeedback, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));
                }
            }


            CosmosDocFeedback feedbackDoc = await CosmosAPI.cosmosDBClientFeedback.FindFeedback(tsFeedback.UserID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            if (feedbackDoc != null)
            {
                return(feedbackDoc.toTSFeedback());
            }
            else
            {
                return(new TSFeedback());
            }
        }
 public async Task <TSFeedback> GetFeedback(TSFeedback tsFeedback, List <string> CallTrace)
 {
     return((await cosmosDBClientBase.GetItemAsync(new CosmosDocFeedback(tsFeedback), pkPrefix, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()))).toTSFeedback());
 }
 public async Task <bool> UpdateFeedback(TSFeedback tsFeedback, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.UpdateItemAsync(new CosmosDocFeedback(tsFeedback), LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }
        public async Task <ActionResult <TSFeedback> > AddFeedback([FromBody] TSFeedback TSFeedback)
        {
            GlobalFunctions.CmdDecryptEntityAsymm(TSFeedback);

            TSFeedback.UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(TSFeedback.UserID, "Add or update Feedback", MethodBase.GetCurrentMethod());

            string userName = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10);

            if (!string.IsNullOrEmpty(TSFeedback.UserID))
            {
                if (userName.Equals("demouser"))
                {
                    return(new TSFeedback());
                }
            }



            TSFeedbackEntity oldFeedback = await TS.FindFeedback(TSFeedback.UserID, true, string.Empty);

            if (oldFeedback is null)
            {
                string a = await TS.GetNewID("AllUsers", "LastFeedbackID", false);

                TSFeedback.FeedbackID = int.Parse(a);


                bool b = await TS.AddFeedback(TSFeedback);

                if (b)
                {
                    await GlobalFunctions.NotifyAdmin("New Feedback " + userName + " " + TSFeedback.Text);

                    await TS.UpdateSettingCounter("AllUsers", "FeedbackCount", true);
                }
            }
            else
            {
                if (oldFeedback.Text != TSFeedback.Text)
                {
                    bool b = await TS.UpdateFeedback(TSFeedback);

                    if (b)
                    {
                        await GlobalFunctions.NotifyAdmin("Feedback update to " + TSFeedback.Text + " " + userName);
                    }
                }
            }



            SymmKeyAndIV ClientSymmKeyAndIV = new SymmKeyAndIV
            {
                Key = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmKey", 5),
                IV  = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "ClientSymmIV", 10)
            };


            if (!string.IsNullOrEmpty(ClientSymmKeyAndIV.Key))
            {
                TSFeedbackEntity feedbackEntity = await TS.FindFeedback(TSFeedback.UserID, true, string.Empty);

                if (feedbackEntity != null)
                {
                    TSFeedback result = feedbackEntity.toTSFeedback();
                    GlobalFunctions.CmdEncryptEntitySymm(result, ClientSymmKeyAndIV);
                    return(result);
                }
                else
                {
                    return(new TSFeedback());
                }
            }
            else
            {
                return(new TSFeedback());
            }
        }
 public TSFeedbackEntity(TSFeedback tsFeedback)
 {
     PartitionKey = tsFeedback.UserID;
     RowKey       = tsFeedback.FeedbackID.ToString();
     Text         = tsFeedback.Text;
 }