/// <summary> /// Function to toggle from favorite to not favorite and vice versa /// </summary> /// <param name="FlagId"></param> /// <param name="UserId"></param> /// <returns></returns> public bool FavoriteFlag(int flagId, String userId) { try { if (AddedByUser(userId, flagId)) { // flag is added by user changes in Flag table only _flag = new Flag(); _flag = _sDACEntities.Flags.First(i => i.FlagId == flagId); if (IsFav(flagId)) { // make to unfavorite _flag.IsFavorite = false; } else { // make to favorite _flag.IsFavorite = true; } _sDACEntities.SaveChanges(); return true; } else { if (IsInPublicFavorite(flagId, userId)) { // already exist i.e it is favorite delete it _publicFavorite = (from _publicFav in _sDACEntities.PublicFavorites where (_publicFav.UserId == userId && _publicFav.FlagId == flagId) select _publicFav).First(); _sDACEntities.DeleteObject(_publicFavorite); _sDACEntities.SaveChanges(); return true; } else { _publicFavorite = new PublicFavorite(); _publicFavorite.UserId = userId; _publicFavorite.FlagId = flagId; _sDACEntities.AddToPublicFavorites(_publicFavorite); _sDACEntities.SaveChanges(); return true; } } } catch (Exception Ex) { return false; } }
/// <summary> /// Deprecated Method for adding a new object to the PublicFavorites EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToPublicFavorites(PublicFavorite publicFavorite) { base.AddObject("PublicFavorites", publicFavorite); }
/// <summary> /// function to make aggregate flag favorite /// </summary> /// <param name="AgggregateFlagId"></param> /// <param name="UserId"></param> /// <returns></returns> public bool AggregatetFavoriteFlag(int agggregateFlagId, String userId) { try { if (AggregatetAddedByUser(userId, agggregateFlagId)) { // flag is added by user changes in Flag table only _aggregateFlag = new AggregateFlag(); _aggregateFlag = _sDACEntities.AggregateFlags.First(i => i.AggregateFlagId == agggregateFlagId); if (IsAggregateIsFav(agggregateFlagId)) { // make to unfavorite _aggregateFlag.IsFavorite = false; } else { // make to favorite _aggregateFlag.IsFavorite = true; } _sDACEntities.SaveChanges(); return true; } else { if (IsAggregateInPublicFavorite(agggregateFlagId, userId)) { // already exist i.e it is favorite delete it _publicFavorite = (from _publicFav in _sDACEntities.PublicFavorites where (_publicFav.UserId == userId && _publicFav.FlagId == agggregateFlagId && _publicFav.IsAggregate == true) select _publicFav).First(); _sDACEntities.DeleteObject(_publicFavorite); _sDACEntities.SaveChanges(); return true; } else { try { _publicFavorite = new PublicFavorite(); _publicFavorite.UserId = userId; _publicFavorite.FlagId = agggregateFlagId; _publicFavorite.IsAggregate = true; _sDACEntities.PublicFavorites.AddObject(_publicFavorite); _sDACEntities.SaveChanges(); return true; } catch (Exception Ex) { throw Ex; } } } } catch (Exception Ex) { throw Ex; // return false; } }
/// <summary> /// Create a new PublicFavorite object. /// </summary> /// <param name="publicPrivateId">Initial value of the PublicPrivateId property.</param> /// <param name="userId">Initial value of the UserId property.</param> public static PublicFavorite CreatePublicFavorite(global::System.Int32 publicPrivateId, global::System.String userId) { PublicFavorite publicFavorite = new PublicFavorite(); publicFavorite.PublicPrivateId = publicPrivateId; publicFavorite.UserId = userId; return publicFavorite; }