/// <summary>
        /// function to add aggregate flag
        /// </summary>
        /// <param name="AggregateFlagName"></param>
        /// <param name="AggregateDescription"></param>
        /// <param name="AggregateKeyword"></param>
        /// <param name="IsPublic"></param>
        /// <param name="FlagId"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public bool AddAggregateFlag(String aggregateFlagName, String aggregateDescription, String aggregateKeyword, bool isPublic, int[] flagId, String userId)
        {
            if (AggregateFlagExist(aggregateFlagName,userId))
            {
                return false;
            }
            else
            {

                _aggregateFlag = new AggregateFlag();

                _aggregateFlag.AggregateFlagName = aggregateFlagName;
                _aggregateFlag.AggregateFlagDescription = aggregateDescription;
                _aggregateFlag.Keyword = aggregateKeyword;
                _aggregateFlag.IsPublic = isPublic;
                _aggregateFlag.UserId = userId;
                _aggregateFlag.CreatedBy = userId;

                _aggregateFlag.CreatedDate = DateTime.Now;
                _aggregateFlag.ModifiedBy = userId;
                _aggregateFlag.ModifiedDate = DateTime.Now;

                _sDACEntities.AddToAggregateFlags(_aggregateFlag);
                _sDACEntities.SaveChanges();

                int AggregateFlagId=GetAggregateFlagById(aggregateFlagName);

                for (int i = 0; i < flagId.Count(); i++)
                {

                        int Flag = flagId[i];
                        if (ExistInAggregateFlag(AggregateFlagId, Flag))
                        {

                        }
                        else
                        {
                            try
                            {

                                _flagAggregateFlag = new FlagAggregateFlag();
                                _flagAggregateFlag.AggregateFlagId = AggregateFlagId;
                                _flagAggregateFlag.FlagId = Flag;
                                _flagAggregateFlag.CreatedBy = userId;
                                _flagAggregateFlag.CreatedDate = DateTime.Now;
                                _flagAggregateFlag.ModifiedBy = userId;
                                _flagAggregateFlag.ModifiedDate = DateTime.Now;
                                _sDACEntities.AddToFlagAggregateFlags(_flagAggregateFlag);
                                _sDACEntities.SaveChanges();
                                _flagAggregateFlag = null;
                            }
                            catch (Exception Ex)
                            {
                            }
                        }

                }

                return true;

            }
        }
        /// <summary>
        /// Function to edit the aggregate flag
        /// </summary>
        /// <param name="AggregateFlagId"></param>
        /// <param name="AggregateFlagName"></param>
        /// <param name="AggregateDescription"></param>
        /// <param name="AggregateKeyword"></param>
        /// <param name="IsPublic"></param>
        /// <param name="FlagId"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public bool EditAddAggregateFlag(int aggregateFlagId, String aggregateFlagName, String aggregateDescription, String aggregateKeyword, bool isPublic, int[] flagId, String userId)
        {
            try
            {
                if (AggregateFlagHasSameName(aggregateFlagId, aggregateFlagName))
                {
                }
                else
                    if (AggregateFlagExist(aggregateFlagName, userId))
                    {
                        return false;
                    }

                _aggregateFlag = new AggregateFlag();
                _aggregateFlag = _sDACEntities.AggregateFlags.First(i => i.AggregateFlagId == aggregateFlagId);
                _aggregateFlag.AggregateFlagName = aggregateFlagName;
                _aggregateFlag.AggregateFlagDescription = aggregateDescription;
                _aggregateFlag.Keyword = aggregateKeyword;
                _aggregateFlag.IsPublic = isPublic;
                _aggregateFlag.ModifiedBy =userId;
                _aggregateFlag.ModifiedDate = DateTime.Now;
                _sDACEntities.SaveChanges();

                // delete all the flags associated with aggregate flag
                DeleteFromFlagAggregateFlagByAggregateFlagId(aggregateFlagId);

                for (int i = 0; i < flagId.Count(); i++)
                {
                    int Flag = flagId[i];
                    if (ExistInAggregateFlag(aggregateFlagId, Flag))
                    {

                    }
                    else
                    {
                        try
                        {
                            _flagAggregateFlag = new FlagAggregateFlag();
                            _flagAggregateFlag.AggregateFlagId = aggregateFlagId;
                            _flagAggregateFlag.FlagId = Flag;
                            _flagAggregateFlag.CreatedBy = userId;
                            _flagAggregateFlag.CreatedDate = DateTime.Now;
                            _flagAggregateFlag.ModifiedBy = userId;
                            _flagAggregateFlag.ModifiedDate = DateTime.Now;
                            _sDACEntities.AddToFlagAggregateFlags(_flagAggregateFlag);
                            _sDACEntities.SaveChanges();
                            _flagAggregateFlag = null;
                        }
                        catch (Exception Ex)
                        {
                        }
                    }

                }

                return true;
            }
            catch (Exception Ex)
            {
                return false;
            }
        }
 /// <summary>
 /// Function to delete the record of Aggregate flag from FlagAggregateFlag table
 /// </summary>
 /// <param name="AggregateFlagId"></param>
 public void DeleteFromFlagAggregateFlagByAggregateFlagId(int aggregateFlagId)
 {
     _flagAggregateFlag = new FlagAggregateFlag();
     try
     {
         var flag = _sDACEntities.FlagAggregateFlags.Where(c => c.AggregateFlagId == aggregateFlagId);
         if (flag.Count() > 0)
         {
             foreach (var c in flag)
             {
                 _sDACEntities.DeleteObject(c);
             }
         }
         _sDACEntities.SaveChanges();
     }
     catch (Exception Ex)
     {
     }
 }
        /// <summary>
        /// Function to delete the aggregate flag
        /// </summary>
        /// <param name="AggregateFlagId"></param>
        /// <returns></returns>
        public bool DeleteAggregateFlag(int aggregateFlagId)
        {
            _flagAggregateFlag = new FlagAggregateFlag();
            _aggregateFlag = new AggregateFlag();
            try
            {

                var flag = _sDACEntities.FlagAggregateFlags.Where(c => c.AggregateFlagId == aggregateFlagId);
                if (flag.Count() > 0)
                {
                    foreach (var c  in flag)
                    {
                        _sDACEntities.DeleteObject(c);
                    }
                }

                _sDACEntities.SaveChanges();

                _aggregateFlag = _sDACEntities.AggregateFlags.First(i => i.AggregateFlagId == aggregateFlagId);
                _aggregateFlag.IsDelete = true;
                _sDACEntities.SaveChanges();

                return true;
            }
            catch (Exception Ex)
            {
                return false;
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the FlagAggregateFlags EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToFlagAggregateFlags(FlagAggregateFlag flagAggregateFlag)
 {
     base.AddObject("FlagAggregateFlags", flagAggregateFlag);
 }
 /// <summary>
 /// Create a new FlagAggregateFlag object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="aggregateFlagId">Initial value of the AggregateFlagId property.</param>
 /// <param name="flagId">Initial value of the FlagId property.</param>
 /// <param name="createdBy">Initial value of the CreatedBy property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 /// <param name="modifiedBy">Initial value of the ModifiedBy property.</param>
 /// <param name="modifiedDate">Initial value of the ModifiedDate property.</param>
 public static FlagAggregateFlag CreateFlagAggregateFlag(global::System.Int32 id, global::System.Int32 aggregateFlagId, global::System.Int32 flagId, global::System.String createdBy, global::System.DateTime createdDate, global::System.String modifiedBy, global::System.DateTime modifiedDate)
 {
     FlagAggregateFlag flagAggregateFlag = new FlagAggregateFlag();
     flagAggregateFlag.Id = id;
     flagAggregateFlag.AggregateFlagId = aggregateFlagId;
     flagAggregateFlag.FlagId = flagId;
     flagAggregateFlag.CreatedBy = createdBy;
     flagAggregateFlag.CreatedDate = createdDate;
     flagAggregateFlag.ModifiedBy = modifiedBy;
     flagAggregateFlag.ModifiedDate = modifiedDate;
     return flagAggregateFlag;
 }