Exemplo n.º 1
0
        public LanguageStringService(IGenericRepository <Language> languaesGR,
                                     IGenericRepository <LanguageString> languageStringGR,
                                     IGenericRepository <LanguageStringType> languageStringTypeGR,
                                     IGenericRepository <LanguageStringIdType> languageStringIdTypeGR,
                                     IGenericRepository <LanguageStringId> languageStringIdGR,
                                     LanguageStringServiceConfiguration configuration,
                                     ScopedHttpContext scopedHttpContext)
        {
            _languaesGR             = languaesGR;
            _languageStringGR       = languageStringGR;
            _languageStringIdTypeGR = languageStringIdTypeGR;
            _languageStringTypeGR   = languageStringTypeGR;
            _languageStringIdGR     = languageStringIdGR;
            _configuration          = configuration;
            _httpContext            = scopedHttpContext.HttpContext;

            if (_httpContext.Request.Headers.ContainsKey("accept-language") && ((String)_httpContext.Request.Headers["accept-language"]).Length == 2)
            {
                _langAddName = _httpContext.Request.Headers["accept-language"];
            }

            if (_langAddName == null || _languaesGR.CountWhere(x => x.AbbName == _langAddName) == 0)
            {
                _langAddName = _configuration.DefaultLanguage;
            }


            /*foreach (var item in arguments)
             *  draftBody = draftBody.ReplaceFirstOccurrance("$arg$", item);
             * return draftBody;*/

            // var m = _languageStringGR.GetDbSet().Where((x) => x.Id == Id && x.Language.AbbName == langAddName).Include(x => x.Language).ToArray().FirstOrDefault();
        }
Exemplo n.º 2
0
 public static void UseLanguageStringService(this IServiceCollection services, LanguageStringServiceConfiguration configuration)
 {
     services.AddSingleton(configuration);
     services.AddScoped <ILanguageStringService, LanguageStringService>();
 }
Exemplo n.º 3
0
        public static void OnInit(ClientErrorManager manager, IValidatingService validatingService, LanguageStringServiceConfiguration configuration)
        {
            manager.AddErrors(new ClientErrors("LanguageStringService", new Dictionary <string, ClientError>
            {
                { "lss-inc-lang-str", new ClientError("Incorrect language string!") },
                { "lss-lng-ald-reg", new ClientError("Language already registered!") },
                { "lss-lng-no-reg", new ClientError("Incorrect language!") },
                { "lss-type-ald-reg", new ClientError("Type already registered!") },
                { "lss-type-no-reg", new ClientError("Incorrect type!") },
                { "lss-strid-ald-reg", new ClientError("String id already registered!") },
                { "lss-strid-no-reg", new ClientError("Incorrect string id!") },
                { "lss-baseupateid-inc", new ClientError("Incorrect base update id!") }
            }));

            validatingService.AddValidateFunc("lss-lng-name", (string som, PropValidateContext ctx) => {
                if (som == null)
                {
                    return;
                }
                else if (som.Length != 2)
                {
                    ctx.Valid.Add($"[lss-inc-lang-str]");
                }
            });

            validatingService.AddValidateFunc("lss-lng-type", (string som, PropValidateContext ctx) => {
                if (som == null)
                {
                    return;
                }
                else if (som.Length > configuration.MaxTypeNameLength)
                {
                    ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxTypeNameLength}]"); //"Too long login(max {_configuration.MaxCountCharsLogin} characters)!"
                }
            });

            validatingService.AddValidateFunc("lss-str-id-name", (string som, PropValidateContext ctx) => {
                if (som == null)
                {
                    return;
                }
                else if (som.Length > configuration.MaxStringIdNameLength)
                {
                    ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxStringIdNameLength}]");
                }
            });

            validatingService.AddValidateFunc("lss-str-name", (string som, PropValidateContext ctx) => {
                if (som == null)
                {
                    return;
                }
                else if (som.Length > configuration.MaxStringLength)
                {
                    ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxStringLength}]");
                }
            });

            validatingService.AddValidateFunc("lss-lng-full-name", (string som, PropValidateContext ctx) => {
                if (som == null)
                {
                    return;
                }
                else if (som.Length > configuration.MaxLangFullNameLength)
                {
                    ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxLangFullNameLength}]");
                }
            });
        }