Exemplo n.º 1
0
        private static DictData GetPronounce(string word)
        {
            word = pluralizer.Singularize(word);
            string us = null, usvoice = null;

            try
            {
                string cs = @"URI=file:dict.db";

                using var con = new SQLiteConnection(cs);
                con.Open();

                string stm = "select uk,us,ukvoice,usvoice from english where word='" + word.ToLower() + "' limit 1";
                using var cmd = new SQLiteCommand(stm, con);
                using SQLiteDataReader rdr = cmd.ExecuteReader();


                while (rdr.Read())
                {
                    us      = rdr.GetString(1);
                    usvoice = rdr.GetString(3);
                }
            }
            catch (Exception ex) { }

            return(new DictData(us, usvoice, word));
        }
        private static string GetValidName(string typeName, bool singularize = false)
        {
            if (singularize && _pluralizer.IsPlural(typeName))
            {
                typeName = _pluralizer.Singularize(typeName);
            }

            List <char> newTypeName   = new List <char>();
            bool        nextCharUpper = true;

            for (int i = 0; i < typeName.Length; i++)
            {
                if (typeName[i] == ' ')
                {
                    nextCharUpper = true;
                    continue;
                }

                if (nextCharUpper)
                {
                    nextCharUpper = false;
                    if (!char.IsUpper(typeName[i]))
                    {
                        newTypeName.Add(char.ToUpper(typeName[i], CultureInfo.InvariantCulture));
                        continue;
                    }
                }

                newTypeName.Add(typeName[i]);
            }

            return(new string(newTypeName.ToArray()));
        }
Exemplo n.º 3
0
        public void Generate(IDbExtractor reader, DbConnection connection, string tableName, string path)
        {
            string pascalCaseName = ToPascalCase(tableName);
            string fileName       = pluralizer.Singularize(pascalCaseName);
            string filePath       = Path.Combine(path, $"{fileName}.cs");

            using var fileStream = File.Create(filePath);
            using var fileWriter = new StreamWriter(fileStream);

            var columns = reader.GetColumns(connection, tableName);

            fileWriter.WriteLine("using System.ComponentModel.DataAnnotations;");
            fileWriter.WriteLine("using System.ComponentModel.DataAnnotations.Schema;");
            fileWriter.WriteLine();
            fileWriter.WriteLine("namespace Entities");
            fileWriter.WriteLine("{");
            fileWriter.WriteLine(1, $"[Table(\"{tableName}\")]");
            fileWriter.WriteLine(1, $"public class {fileName}");
            fileWriter.WriteLine(1, "{");
            foreach (var columnInfo in columns)
            {
                var propName = ToPascalCase(columnInfo.ColumnName);
                var type     = TypeNameOrAlias(columnInfo.ColumnType);
                if (columnInfo.IsPrimaryKey)
                {
                    fileWriter.WriteLine(2, "[Key]");
                }

                fileWriter.WriteLine(2, $"[Column(\"{propName}\")]");
                if (columnInfo.IsNullable && columnInfo.ColumnType != typeof(string))
                {
                    type += "?";
                }

                fileWriter.WriteLine(2, "public ", type, " ", propName,
                                     " { get; set; }");

                var last = columns.Last();
                if (!columnInfo.Equals(last))
                {
                    fileWriter.WriteLine();
                }
            }

            fileWriter.WriteLine(1, "}");
            fileWriter.WriteLine("}");
        }
Exemplo n.º 4
0
        public async Task OnGetAsync()
        {
            var recipes = new List <Recipe>();

            UserId = _userManager.GetUserId(User);
            var searchItems       = SearchString?.Split(',').Select(x => x.Trim()).Select(x => x.ToLower()).ToList();
            var robustSearchItems = new List <string>();

            if (searchItems != null)
            {
                foreach (var searchItem in searchItems)
                {
                    robustSearchItems.Add(_pluralizer.Singularize(searchItem));
                    robustSearchItems.Add(_pluralizer.Pluralize(searchItem));
                }
            }

            recipes = _context.Recipe
                      .Join(_context.Ingredient, a => a.ID, b => b.RecipeId, (a, b) => a).Distinct()
                      .Where(x => x.UserRecordNumber.Equals(UserId))
                      .Select(recipe => new Recipe
            {
                ID = recipe.ID,
                UserRecordNumber = recipe.UserRecordNumber.ToString(),
                Title            = recipe.Title,
                DateAdded        = recipe.DateAdded,
                Instruction      = recipe.Instruction,
                Ingredients      = recipe.Ingredients
                                   .Select(ingredient => new Ingredient
                {
                    ID          = ingredient.ID,
                    RecipeId    = ingredient.RecipeId,
                    Name        = ingredient.Name,
                    Measurement = ingredient.Measurement,
                    Notes       = ingredient.Notes,
                    Quantity    = ingredient.Quantity
                }).ToList()
            }).ToList();

            if (!string.IsNullOrEmpty(SearchString))
            {
                var recipesFromSearch = new List <Recipe>();
                recipesFromSearch.AddRange(recipes.Where(x => robustSearchItems.Any(y => x.Title.ToLower().Contains(y))));

                foreach (var recipe in recipes)
                {
                    foreach (var ingredient in recipe.Ingredients)
                    {
                        if (robustSearchItems.Any(x => ingredient.Name.ToLower().Contains(x)))
                        {
                            if (!recipesFromSearch.Contains(recipe))
                            {
                                recipesFromSearch.Add(recipe);
                                break;
                            }
                        }
                    }
                }

                recipes = recipesFromSearch;
            }

            Recipe = recipes;
        }