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!");
            }
        }
示例#2
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!"));
            }
        }
示例#3
0
 public async Task <bool> UpdateEntity(CosmosDocUIWordForeign tsUIWordForeign, List <string> CallTrace)
 {
     return(await cosmosDBClientBase.UpdateItemAsync(tsUIWordForeign, LocalFunctions.AddThisCaller(CallTrace, MethodBase.GetCurrentMethod())));
 }