Beispiel #1
0
        public async Task <ActionResult> Update(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "uiwordforeign/update")] HttpRequest req,
            ILogger log)
        {
            TSUIWordForeign tsUIWordForeign = await MyFromBody <TSUIWordForeign> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum>
            {
                WebApiUserTypesEnum.Admin
            };

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


            bool b = await CosmosAPI.cosmosDBClientUIWordForeign.Update(tsUIWordForeign, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

            if (b)
            {
                return(new OkObjectResult("OK"));
            }
            else
            {
                return(new OkObjectResult("Error:Can't add new todo!"));
            }
        }
        private static bool AddUIWordForeign(string Lang, string NativeWord, string ForeignWord, bool IsHuman, List <string> CallTrace)
        {
            if (string.IsNullOrEmpty(NativeWord))
            {
                throw new ArgumentException("native word is empty!");
            }

            if (string.IsNullOrEmpty(ForeignWord))
            {
                throw new ArgumentException("foreign word is empty!");
            }


            NativeWord = NativeWord.ToLower();


            Guid UIWordNativeID;

            Guid UILanguageID;



            if (UINativeWordsDict.TryGetValue(NativeWord, out UIWordNativeID))
            {
                if (UILangDict.TryGetValue(Lang, out UILanguageID))
                {
                    CosmosDocUIWordForeign UIWordForeign = CosmosAPI.cosmosDBClientUIWordForeign.FindByWordAndNativeWordID(ForeignWord, UIWordNativeID, TodosCosmos.LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())).Result;

                    if (UIWordForeign is null)
                    {
                        TSUIWordForeign uiWordForeign = new TSUIWordForeign
                        {
                            ID             = Guid.NewGuid(),
                            Word           = ForeignWord,
                            UILanguageID   = UILanguageID,
                            UIWordNativeID = UIWordNativeID,
                            Human          = IsHuman
                        };


                        return(CosmosAPI.cosmosDBClientUIWordForeign.Add(uiWordForeign, TodosCosmos.LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())).Result);
                    }
                    else
                    {
                        return(false);
                        //throw new ArgumentException("word " + ForeignWord + " with same foreign word id exists already! value in base - " + UIWordForeign.Word);
                    }
                }
                else
                {
                    throw new ArgumentException("language " + Lang + " does not exists!");
                }
            }
            else
            {
                throw new ArgumentException("native word " + NativeWord + " does not exists!");
            }
        }
Beispiel #3
0
        public CosmosDocUIWordForeign(TSUIWordForeign tsUIWordForeign)
        {
            ID             = tsUIWordForeign.ID;
            Word           = tsUIWordForeign.Word;
            UIWordNativeID = tsUIWordForeign.UIWordNativeID;
            UILanguageID   = tsUIWordForeign.UILanguageID;
            Human          = tsUIWordForeign.Human;

            DocType = (int)DocTypeEnum.UIWordForeign;
            GeneratePK();
        }
Beispiel #4
0
        public async Task <ActionResult <IEnumerable <TSUIWordForeign> > > GetAllByLang(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "uiwordforeign/getallbylang")] HttpRequest req,
            ILogger log)
        {
            TSUIWordForeign tsUIWordForeign = await MyFromBody <TSUIWordForeign> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));


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


            return(await CosmosAPI.cosmosDBClientUIWordForeign.GetAllByLang(tsUIWordForeign.UILanguageID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod())));
        }
Beispiel #5
0
        public async Task <ActionResult <TSUIWordForeign> > Get(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "uiwordforeign/get")] HttpRequest req,
            ILogger log)
        {
            TSUIWordForeign tsUIWordForeign = await MyFromBody <TSUIWordForeign> .FromBody(req, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));


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


            TSUIWordForeign result = await CosmosAPI.cosmosDBClientUIWordForeign.Get(tsUIWordForeign, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));



            if (result is null)
            {
                return(new TSUIWordForeign());
            }
            else
            {
                return(result);
            }
        }
Beispiel #6
0
        public async Task <ActionResult> Add(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "uiwordforeign/add")] HttpRequest req,
            ILogger log)
        {
            List <WebApiUserTypesEnum> localAllowedRoles = new List <WebApiUserTypesEnum>
            {
                WebApiUserTypesEnum.Admin
            };

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

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



            CosmosDocUIWordForeign l = await CosmosAPI.cosmosDBClientUIWordForeign.FindByWordAndNativeWordID(tsUIWordForeign.Word, tsUIWordForeign.UIWordNativeID, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));


            if (l is null)
            {
                bool b = await CosmosAPI.cosmosDBClientUIWordForeign.Add(tsUIWordForeign, TodosCosmos.LocalFunctions.AddThisCaller(new List <string>(), MethodBase.GetCurrentMethod()));

                if (b)
                {
                    return(new OkObjectResult("OK"));
                }
                else
                {
                    return(new OkObjectResult("Error:Can't add new UIWordForeign!"));
                }
            }
            else
            {
                return(new OkObjectResult("Error:UIWordForeign with word - " + tsUIWordForeign.Word + " and same NativeWordID exists already!"));
            }
        }
Beispiel #7
0
        public static async Task <List <TSUIWordForeign> > CmdGetAllUIWordForeigns(Guid LangID)
        {
            try
            {
                httpClient.DefaultRequestHeaders.Accept.Clear();
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LocalData.CurrJWT);

                TSUIWordForeign tmpWordForeign = new TSUIWordForeign {
                    UILanguageID = LangID
                };



                List <TSUIWordForeign> result = await httpClient.MyPostJsonGetJsonEnumAsync <List <TSUIWordForeign>, TSUIWordForeign>("uiwordForeign/getallbylang", tmpWordForeign);

                return(result);
            }
            catch (Exception ex)
            {
                LocalFunctions.AddError(ex.Message, MethodBase.GetCurrentMethod(), true, false);
                return(new List <TSUIWordForeign>());
            }
        }
Beispiel #8
0
 public async Task <TSUIWordForeign> Get(TSUIWordForeign tsUIWordForeign, List <string> CallTrace)
 {
     return((await cosmosDBClientBase.GetItemAsync(new CosmosDocUIWordForeign(tsUIWordForeign), pkPrefix, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod()))).toTSUIWordForeign());
 }
Beispiel #9
0
 public async Task <bool> Update(TSUIWordForeign tsUIWordForeign, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.UpdateItemAsync(new CosmosDocUIWordForeign(tsUIWordForeign), LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }