public IActionResult Modify(int id) { var recipe = RecipesService.GetById(id); var recipeModify = ModelConverter.ConvertToRecipeModify(recipe); return(View(recipeModify)); }
public ActionResult <Recipe> Get(int id) { try { return(Ok(_rs.GetById(id))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Recipe> GetById(int id) { try { Recipe found = _service.GetById(id); return(Ok(found)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task GetByIdShouldReturnTheExpectedType() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; AutoMapperConfig.RegisterMappings(Assembly.Load("CookingBook.Web.ViewModels")); var dbContext = new ApplicationDbContext(options); var category = new Category(); var nutrValue = new NutritionValue(); var user = new ApplicationUser(); var prod = new Collection <RecipeByIdProductsViewModel>(); dbContext.Recipes.Add(new Recipe { Id = "a", CreatedOn = DateTime.Parse("2008-11-01T19:31:00.0000000Z"), Title = "newTitle1", CategoryId = 1, }); dbContext.Recipes.Add(new Recipe { Id = "b", CreatedOn = DateTime.Parse("2008-11-01T19:32:00.0000000Z"), Title = "newTitle2", CategoryId = 1, }); dbContext.Recipes.Add(new Recipe { Id = "c", CreatedOn = DateTime.Parse("2008-11-01T19:33:00.0000000Z"), Title = "newTitle3", CategoryId = 2, }); await dbContext.SaveChangesAsync(); var recipeRepo = new EfDeletableEntityRepository <Recipe>(dbContext); var nutritionRepo = new EfDeletableEntityRepository <NutritionValue>(dbContext); var productRepo = new EfDeletableEntityRepository <Product>(dbContext); var userRepo = new EfDeletableEntityRepository <ApplicationUser>(dbContext); var service = new RecipesService(recipeRepo, nutritionRepo, productRepo, userRepo); Assert.IsType <RecipeDTO>(service.GetById <RecipeDTO>("a")); Assert.IsNotType <RecipeDTO>(service.GetById <RecipeDTO>("asd")); }
public ActionResult <Recipe> GetById(long id) { var result = RecipeService.GetById(id); if (result != null) { result.RecipeAuthor.PasswordHash = null; result.RecipeAuthor.PasswordSalt = null; return(Ok(result)); } else { return(BadRequest()); } }