public async Task <ActionResult <Favorite> > PostFavorite(Favorite favorite) { var createFavorite = new FavoritesCreate { Favorite = favorite }; return(await createFavorite.Excute()); }
public ActionResult AddToFavorites(int id) { var service = CreateFavoriteService(); var favorite = new FavoritesCreate { SocialId = id }; if (service.CreateFavorites(favorite)) { TempData["SaveResult"] = "Added to favorites"; return(RedirectToAction("Index")); } TempData["SaveResult"] = "Already added to favorites"; return(RedirectToAction("Index")); }
public bool CreateFavorites(FavoritesCreate model) { var entity = new Favorites() { OwnerId = _userId, EmotionalId = model.EmotionalId, PhysicalId = model.PhysicalId, SocialId = model.SocialId, FinancialId = model.FinancialId, }; using (var ctx = new ApplicationDbContext()) { try { if (model.EmotionalId != null) { var checkForFavorite = ctx.Favorites.Single(e => e.EmotionalId == entity.EmotionalId && e.OwnerId == _userId); } if (model.PhysicalId != null) { var checkForFavorite = ctx.Favorites.Single(e => e.PhysicalId == entity.PhysicalId && e.OwnerId == _userId); } if (model.SocialId != null) { var checkForFavorite = ctx.Favorites.Single(e => e.SocialId == entity.SocialId && e.OwnerId == _userId); } if (model.FinancialId != null) { var checkForFavorite = ctx.Favorites.Single(e => e.FinancialId == entity.FinancialId && e.OwnerId == _userId); } return(false); } catch { } ctx.Favorites.Add(entity); ctx.SaveChanges(); return(true); } }