Пример #1
0
        IEnumerable <RecipeModel> IRecipeRepository.GetAll()
        {
            //IEnumerable<RecipeModel> listOfRecipe = (from objRecipe in db.Recipes
            //                                         select new RecipeModel()
            //                                         {
            //                                             RecipeId = objRecipe.RecipeId,
            //                                             ProductName = objRecipe.ProductName,
            //                                             Variation = objRecipe.Variation,
            //                                             CurrentPrice = objRecipe.CurrentPrice,
            //                                             LastCost = objRecipe.LastCost,
            //                                             Description = objRecipe.Description,
            //                                             StandardRecipeId = objRecipe.StandardRecipeId,
            //                                             OperatorId = objRecipe.OperatorId,
            //                                             OperatorLocationId = objRecipe.OperatorLocationId,
            //                                             date_creation = objRecipe.date_creation,
            //                                             created_by = objRecipe.created_by,
            //                                             modified_by = objRecipe.modified_by,
            //                                             date_modified = objRecipe.date_modified
            //                                         }).ToList();
            //return listOfRecipe;

            var Recipeconfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Recipe, RecipeModel>();
            });

            var listOfRecipe = from rec in db.Recipes
                               select rec;
            var recipe = new List <RecipeModel>();

            if (listOfRecipe.Any())
            {
                foreach (var rec in listOfRecipe)
                {
                    IMapper     mapper      = Recipeconfig.CreateMapper();
                    var         source      = new Recipe();
                    var         dest        = mapper.Map <Recipe, RecipeModel>(source);
                    RecipeModel recipeModel = mapper.Map <Recipe, RecipeModel>(rec);
                    recipe.Add(recipeModel);
                }
            }
            return(recipe);
        }
Пример #2
0
        public void AddRecipe(RecipeModel recipeModel)
        {
            Recipe objRecipe = new Recipe()
            {
                RecipeId           = recipeModel.RecipeId,
                ProductName        = recipeModel.ProductName,
                Variation          = recipeModel.Variation,
                CurrentPrice       = recipeModel.CurrentPrice,
                LastCost           = recipeModel.LastCost,
                Description        = recipeModel.Description,
                StandardRecipeId   = recipeModel.StandardRecipeId,
                OperatorId         = recipeModel.OperatorId,
                OperatorLocationId = recipeModel.OperatorLocationId,
                date_creation      = recipeModel.date_creation,
                created_by         = recipeModel.created_by,
                modified_by        = recipeModel.modified_by,
                date_modified      = recipeModel.date_modified
            };

            db.Recipes.Add(objRecipe);
            db.SaveChanges();
        }