Exemplo n.º 1
0
        public IActionResult GetIngredient(Guid id)
        {
            var ingredient = service.GetIngredientById(id);
            var viewModel  = mapper.Map(ingredient);

            return(View(nameof(GetIngredient), viewModel));
        }
Exemplo n.º 2
0
        public RecipeViewModel Map(Recipe model)
        {
            var viewModel = new RecipeViewModel
            {
                Id                 = model.Id,
                Description        = model.Description,
                Title              = model.Title,
                SourceURL          = model.SourceURL,
                CookingTimeMinutes = model.CookingTimeMinutes,
                Stages             = model.Stages?.Select(s => stageMapper.Map(s)).ToList(),
                Ingredients        = model.Ingredients?.Select(i => ingredientMapper.Map(i)).ToList(),
                DishType           = model.DishType?.Name,
                CookingType        = model.CookingType?.Name,
                RecipeType         = model.RecipeType?.Name
            };

            if (model.Thumbnail != null)
            {
                viewModel.Thumbnail = new ImageViewModel
                {
                    Base64    = Convert.ToBase64String(model.Thumbnail.Content),
                    Extension = model.Thumbnail.Extension
                };
            }
            ;

            if (model.CookingType?.Icon != null)
            {
                viewModel.CookingTypeIcon = new ImageViewModel
                {
                    Base64    = Convert.ToBase64String(model.CookingType.Icon.Content),
                    Extension = model.CookingType.Icon.Extension
                };
            }
            if (model.RecipeType?.Icon != null)
            {
                viewModel.RecipeTypeIcon = new ImageViewModel
                {
                    Base64    = Convert.ToBase64String(model.RecipeType.Icon.Content),
                    Extension = model.RecipeType.Icon.Extension
                };
            }
            if (model.DishType?.Icon != null)
            {
                viewModel.DishTypeIcon = new ImageViewModel
                {
                    Base64    = Convert.ToBase64String(model.DishType.Icon.Content),
                    Extension = model.DishType.Icon.Extension
                };
            }

            return(viewModel);
        }