public ActionResult Create(FavoriteCreate model) { if (ModelState.IsValid) { return(View(model)); } var userId = Guid.Parse(User.Identity.GetUserId()); var services = new FavoriteService(userId); services.CreateFavorite(model); return(RedirectToAction("Index")); }
public bool CreateFavorite(FavoriteCreate model) { var entity = new Favorite() { OwnerId = _userId, RecipeName = model.RecipeName, Directions = model.Directions, Ingredients = model.Ingredients, Origin = model.Origin, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Favorites.Add(entity); return(ctx.SaveChanges() == 1); } }