RecipeIngredient Map(Data.Models.RecipeIngredient dataModel) { return(new RecipeIngredient { Id = dataModel.Id, IngredientName = dataModel.Ingredient?.Name, UnitAbbr = dataModel.Unit?.Abbr, Quantity = dataModel.Quantity }); }
async Task <Data.Models.RecipeIngredient> Map(RecipeIngredient viewModel) { var unit = await _db.Units.SingleOrDefaultAsync(u => u.Abbr == viewModel.UnitAbbr); var ingredient = await _db.Ingredients.SingleOrDefaultAsync(ing => ing.Name == viewModel.IngredientName); var recipeIngredient = new Data.Models.RecipeIngredient { Id = viewModel.Id, Ingredient = ingredient, Unit = unit, Quantity = viewModel.Quantity }; return(recipeIngredient); }