コード例 #1
0
        public async Task <ActionResult <TSCategory> > Get([FromBody] TSCategory TSCategory)
        {
            string UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(UserID, "Requested Category", 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))
            {
                TSCategory result = await TS.GetCategory(TSCategory);

                GlobalFunctions.CmdEncryptEntitySymm(result, ClientSymmKeyAndIV);


                return(result);
            }
            else
            {
                return(new TSCategory());
            }
        }
コード例 #2
0
        public async Task <ActionResult> Update(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "category/update")] HttpRequest req,
            ILogger log)
        {
            TSCategory tsCategory = await MyFromBody <TSCategory> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

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


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



            bool b = await CosmosAPI.cosmosDBClientCategory.UpdateCategory(tsCategory, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            if (b)
            {
                return(new OkObjectResult("OK"));
            }
            else
            {
                return(new OkObjectResult("Error:Can't add new Category!"));
            }
        }
コード例 #3
0
        public CosmosDocCategory(TSCategory tsCategory)
        {
            UserID = tsCategory.UserID;
            ID     = tsCategory.ID;
            Name   = tsCategory.Name;

            DocType = (int)DocTypeEnum.Category;
            GeneratePK();
        }
コード例 #4
0
        public async Task <bool> AddDefaultCategory(Guid UserID, List <string> CallTrace)
        {
            TSCategory tsCategory = new TSCategory();

            tsCategory.ID     = Guid.NewGuid();
            tsCategory.UserID = UserID;
            tsCategory.Name   = "default";

            return(await AddCategory(tsCategory, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
        }
コード例 #5
0
        public async Task <ActionResult <TSCategory> > Get(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "category/get")] HttpRequest req,
            ILogger log)
        {
            TSCategory tsCategory = await MyFromBody <TSCategory> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

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


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



            return(await CosmosAPI.cosmosDBClientCategory.GetCategory(tsCategory, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));
        }
コード例 #6
0
        public async Task <ActionResult> Put([FromBody] TSCategory TSCategory)
        {
            string UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            await TS.AddActivityLog(UserID, "put Category", MethodBase.GetCurrentMethod());

            GlobalFunctions.CmdDecryptEntityAsymm(TSCategory);

            bool b = await TS.UpdateCategory(TSCategory);

            if (b)
            {
                return(Ok("OK"));
            }
            else
            {
                return(Ok("Error:Can't add new Category!"));
            }
        }
コード例 #7
0
        public static async Task <string> CmdAddCategory(TSCategory ParTSCategory)
        {
            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalData.CurrJWT);

            GlobalFunctions.CmdTrimEntity(ParTSCategory);

            TSCategory tsCategoryForSend = GlobalFunctions.CopyObject <TSCategory>(ParTSCategory);


            string result = await httpClient.PostJsonAsync <string>("category/add", tsCategoryForSend);


            httpClient.DefaultRequestHeaders.Accept.Clear();


            return(result);
        }
コード例 #8
0
        public static async Task <string> CmdDeleteCategory(TSCategory ParTSCategory)
        {
            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalData.CurrJWT);

            GlobalFunctions.CmdTrimEntity(ParTSCategory);


            TSCategory tsCategoryForSend = new TSCategory();

            tsCategoryForSend.UserID = ParTSCategory.UserID;
            tsCategoryForSend.ID     = ParTSCategory.ID;

            string result = await httpClient.SendJsonAsync <string>(HttpMethod.Delete, "category/delete", tsCategoryForSend);


            httpClient.DefaultRequestHeaders.Accept.Clear();


            return(result);
        }
コード例 #9
0
        public async Task <ActionResult> Post([FromBody] TSCategory TSCategory)
        {
            string userID   = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);
            string userName = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserName", 10);
            await TS.AddActivityLog(userID, "post Category", MethodBase.GetCurrentMethod());

            GlobalFunctions.CmdDecryptEntityAsymm(TSCategory);
            string a = await TS.GetNewID(TSCategory.UserID, "LastCategoryID", false);

            TSCategory.CategoryID = int.Parse(a);

            bool b = await TS.AddCategory(TSCategory);

            if (b)
            {
                await GlobalFunctions.NotifyAdmin("New category " + userName + " " + TSCategory.Name);

                return(Ok("OK"));
            }
            else
            {
                return(Ok("Error:Can't add new Category!"));
            }
        }
コード例 #10
0
 public TSCategoryEntity(TSCategory tsCategory)
 {
     PartitionKey = tsCategory.UserID;
     RowKey       = tsCategory.CategoryID.ToString();
     Name         = tsCategory.Name;
 }
コード例 #11
0
 public async Task <TSCategory> GetCategory(TSCategory tsCategory, List <string> CallTrace)
 {
     return((await cosmosDBClientBase.GetItemAsync(new CosmosDocCategory(tsCategory), pkPrefix, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()))).toTSCategory());
 }
コード例 #12
0
 public async Task <bool> UpdateCategory(TSCategory tsCategory, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.UpdateItemAsync(new CosmosDocCategory(tsCategory), LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }