Exemplo n.º 1
0
        public static webObject editFriendCollection(FriendCollection aFriendCollection)
        {
            FanToken vFanToken = ServerSession.GetFanToken(HttpContext.Current.Session);

            ServerSession.ClearSessionBusiness(HttpContext.Current.Session);
            webObject vWebObject = new webObject();

            vWebObject.aTransactionStatus = ServerSession.GetTransactionStatus(HttpContext.Current.Session);

            try
            {
                FanServiceConsumer.SaveFriend(vFanToken, aFriendCollection);
                vWebObject.aTransactionStatus.TransactionResult = TransactionResult.OK;
                vWebObject.aTransactionStatus.Message           = "FriendCollection Edited";
                ServerSession.SetTransactionStatus(HttpContext.Current.Session, vWebObject.aTransactionStatus);
                vWebObject.AnObject = aFriendCollection;
            }
            catch (TransactionStatusException tx)
            {
                vWebObject.aTransactionStatus.AssignFromSource(tx.TransactionStatus);
                return(vWebObject);
            }
            catch (Exception ex)
            {
                vWebObject.aTransactionStatus.TransactionResult = TransactionResult.GeneralException;
                vWebObject.aTransactionStatus.Message           = "Edit of FriendCollection unsuccesful" + ex.Message;
                vWebObject.aTransactionStatus.InnerMessage      = ex.InnerException == null ? String.Empty : ex.InnerException.Message;
                return(vWebObject);
            }
            return(vWebObject);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Save a <see cref="Friend" /> list passed as an argument.
        /// </summary>
        /// <param name="aFanKey">A <see cref="FanKey" /> object.</param>
        /// <param name="aFriendCollection">A fan fed collection.</param>
        /// <exception cref="Zephry.ZpAccessException">Access Denied; Friend</exception>
        /// <exception cref="ArgumentNullException">If <c>aFriend</c> argument is <c>null</c>.</exception>
        public static void Save(FanKey aFanKey, FriendCollection aFriendCollection)
        {
            if (aFriendCollection == null)
            {
                throw new ArgumentNullException("Update FriendCollection Business");
            }

            //if (!FanFunctionAccessData.HasModeAccess(aFanKey, "Friend", AccessMode.Update))
            //{
            //    throw new ZpAccessException("Access Denied", String.Format("{0}", aFanKey.FannKey), AccessMode.Update, "Friend");
            //}

            FriendCollection vExisting = new FriendCollection();

            vExisting.IsFiltered = true;
            vExisting.FriendFilter.AssignFromSource(aFriendCollection.FriendFilter);
            FriendData.Load(vExisting);
            FriendCollection vFresh = new FriendCollection();

            vFresh.IsFiltered = true;
            vFresh.FriendFilter.AssignFromSource(aFriendCollection.FriendFilter);

            foreach (Friend vFriend in aFriendCollection.FriendList)
            {
                bool exists         = false;
                bool bonafide       = true;
                int  instancenumber = 0;

                foreach (Friend oldFriend in vExisting.FriendList)
                {
                    if (vFriend.Fan1Key == oldFriend.Fan1Key && vFriend.Fan2Key == oldFriend.Fan2Key)
                    {
                        exists   = true;
                        bonafide = false;
                        instancenumber++;
                        break;
                    }
                    else if (vFriend.Fan1Key == oldFriend.Fan2Key && vFriend.Fan2Key == oldFriend.Fan1Key)
                    {
                        bonafide = false;
                        break;
                    }
                }
                if (bonafide)
                {
                    vFriend.FriendDateEstablished = DateTime.Now.ToLongDateString();
                }
                if ((exists || bonafide) && instancenumber < 2)
                {
                    vFresh.FriendList.Add(vFriend);
                }
            }

            FriendData.Save(vFresh);
        }
Exemplo n.º 3
0
 /// <summary>
 ///   The overloaded Load method that will fill the <c>FriendList</c> property a <see cref="FriendCollection"/> object as an
 ///   ordered <c>List</c> of <see cref="Friend"/>, filtered by the filter properties of the passed <see cref="FriendCollection"/>.
 /// </summary>
 /// <param name="aFriendCollection">The <see cref="FriendCollection"/> object that must be filled.</param>
 /// <remarks>
 ///   The filter properties of the <see cref="FriendCollection"/> must be correctly completed by the calling application.
 /// </remarks>
 /// <exception cref="ArgumentNullException">If <c>aFriendCollection</c> argument is <c>null</c>.</exception>
 public static void Load(FriendCollection aFriendCollection)
 {
     if (aFriendCollection == null)
     {
         throw new ArgumentNullException("aFriendCollection");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = BuildSQL();
         if (aFriendCollection.IsFiltered)
         {
             if (aFriendCollection.FriendFilter.FriendshipFilter.Fan1Key > 0)
             {
                 vStringBuilder.AppendLine("and (t1.FAN_Key = @FAN1Key or t2.FAN_Key = @FAN1Key)");
                 vSqlCommand.Parameters.AddWithValue("@FAN1Key", aFriendCollection.FriendFilter.FriendshipFilter.Fan1Key);
             }
             if (aFriendCollection.FriendFilter.FriendshipFilter.Fan2Key > 0)
             {
                 vStringBuilder.AppendLine("and (t2.FAN_Key = @FAN2Key or t2.FAN_Key = @FAN2Key)");
                 vSqlCommand.Parameters.AddWithValue("@FAN2Key", aFriendCollection.FriendFilter.FriendshipFilter.Fan2Key);
             }
             if (aFriendCollection.FriendFilter.FriendshipFilter.Fan1Name != null)
             {
                 vStringBuilder.AppendFormat("and (t1.FAN_Name like '%{0}%' or t2.FAN_Name like '%{0}%')", aFriendCollection.FriendFilter.FriendshipFilter.Fan1Name);
             }
             if (aFriendCollection.FriendFilter.FriendshipFilter.Fan2Name != null)
             {
                 vStringBuilder.AppendFormat("and (t1.FAN_Name like '%{0}%' or t2.FAN_Name like '%{0}%')", aFriendCollection.FriendFilter.FriendshipFilter.Fan2Name);
             }
         }
         vStringBuilder.AppendLine("order by t3.FRD_DateEstablished");
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader())
         {
             while (vSqlDataReader.Read())
             {
                 var vFriend = new Friend();
                 DataToObject(vFriend, vSqlDataReader, false);
                 aFriendCollection.FriendList.Add(vFriend);
             }
             vSqlDataReader.Close();
         }
         vSqlCommand.Connection.Close();
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Save a <see cref="Friend" /> list passed as an argument.
        /// </summary>
        /// <param name="aFanKey">A <see cref="FanKey" /> object.</param>
        /// <param name="aFriendCollection">A fan fed collection.</param>
        /// <exception cref="Zephry.ZpAccessException">Access Denied; Friend</exception>
        /// <exception cref="ArgumentNullException">If <c>aFriend</c> argument is <c>null</c>.</exception>
        public static void Save(FanKey aFanKey, FriendCollection aFriendCollection)
        {
            if (aFriendCollection == null)
            {
                throw new ArgumentNullException("Update FriendCollection Business");
            }

            //if (!FanFunctionAccessData.HasModeAccess(aFanKey, "Friend", AccessMode.Update))
            //{
            //    throw new ZpAccessException("Access Denied", String.Format("{0}", aFanKey.FannKey), AccessMode.Update, "Friend");
            //}

            FriendCollection vExisting = new FriendCollection();
            vExisting.IsFiltered = true;
            vExisting.FriendFilter.AssignFromSource(aFriendCollection.FriendFilter);
            FriendData.Load(vExisting);
            FriendCollection vFresh = new FriendCollection();
            vFresh.IsFiltered = true;
            vFresh.FriendFilter.AssignFromSource(aFriendCollection.FriendFilter);

            foreach (Friend vFriend in aFriendCollection.FriendList)
            {
                bool exists = false;
                bool bonafide = true;
                int instancenumber = 0;

                foreach (Friend oldFriend in vExisting.FriendList)
                {
                    if (vFriend.Fan1Key == oldFriend.Fan1Key && vFriend.Fan2Key == oldFriend.Fan2Key)
                    {
                        exists = true;
                        bonafide = false;
                        instancenumber++;
                        break;
                    }
                    else if (vFriend.Fan1Key == oldFriend.Fan2Key && vFriend.Fan2Key == oldFriend.Fan1Key)
                    {
                        bonafide = false;
                        break;
                    }
                }
                if (bonafide)
                    vFriend.FriendDateEstablished = DateTime.Now.ToLongDateString();
                if ((exists || bonafide) && instancenumber < 2)
                    vFresh.FriendList.Add(vFriend);
            }

            FriendData.Save(vFresh);
        }
Exemplo n.º 5
0
        /// <summary>
        ///   The overloaded Load method that will return a <see cref="FriendCollection"/>.
        /// </summary>
        /// <param name="aFanKey">A <see cref="FanKey"/> object.</param>
        /// <param name="aFriendCollection">A <see cref="FriendCollection"/> object.</param>
        /// <exception cref="ArgumentNullException">If <c>aFriendCollection</c> argument is <c>null</c>.</exception>
        public static void Load(FanKey aFanKey, FriendCollection aFriendCollection)
        {
            if (aFriendCollection == null)
            {
                throw new ArgumentNullException("Load Friend Business");
            }

            //if (!FanFunctionAccessData.HasModeAccess(aFanKey, "Friend", AccessMode.List))
            //{
            //    throw new ZpAccessException("Access Denied", String.Format("{0}", aFanKey.FannKey), AccessMode.List, "Friend");
            //}

            FriendData.Load(aFriendCollection);

            // REMEMBER TO SORT AFRIENDCOLLECTION SUCH THAT THE FILTERING FAN IS ALWAYS THE FIRST FAN KEY
        }
Exemplo n.º 6
0
        /// <summary>
        ///   The overloaded Load method that will return a <see cref="FriendCollection"/>.
        /// </summary>
        /// <param name="aFanKey">A <see cref="FanKey"/> object.</param>
        /// <param name="aFriendCollection">A <see cref="FriendCollection"/> object.</param>
        /// <exception cref="ArgumentNullException">If <c>aFriendCollection</c> argument is <c>null</c>.</exception>
        public static void Load(FanKey aFanKey, FriendCollection aFriendCollection)
        {
            if (aFriendCollection == null)
            {
                throw new ArgumentNullException("Load Friend Business");
            }

            //if (!FanFunctionAccessData.HasModeAccess(aFanKey, "Friend", AccessMode.List))
            //{
            //    throw new ZpAccessException("Access Denied", String.Format("{0}", aFanKey.FannKey), AccessMode.List, "Friend");
            //}

            FriendData.Load(aFriendCollection);

            // REMEMBER TO SORT AFRIENDCOLLECTION SUCH THAT THE FILTERING FAN IS ALWAYS THE FIRST FAN KEY
        }
Exemplo n.º 7
0
 /// <summary>
 ///   Insert a <see cref="Friend"/> passed as an argument via Stored Procedure that returns the newly inserted Friend Key 
 /// </summary>
 /// <param name="aFriend">A <see cref="Friend"/>.</param>
 /// <exception cref="ArgumentNullException">If <c>aFriend</c> argument is <c>null</c>.</exception>
 public static void Insert(FriendCollection aFriendCollection)
 {
     if (aFriendCollection == null)
     {
         throw new ArgumentNullException("aFriendCollection");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("insert into FRD_Friend");
         vStringBuilder.AppendLine("       (FAN_Key1, FAN_Key2,");
         vStringBuilder.AppendLine("        REL_Key,");
         vStringBuilder.AppendLine("        FRD_DateEstablished)");
         vStringBuilder.AppendLine("values");
         vStringBuilder.AppendLine("       (@FAN1Key, @FAN2Key,");
         vStringBuilder.AppendLine("        @RELKey, @FRDDateEstablished)");
         vStringBuilder.AppendLine(";");
         vSqlCommand.Parameters.Add("@FAN1Key", SqlDbType.Int);
         vSqlCommand.Parameters.Add("@FAN2Key", SqlDbType.Int);
         vSqlCommand.Parameters.Add("@RELKey", SqlDbType.Int);
         vSqlCommand.Parameters.Add("@FRDDateEstablished", SqlDbType.DateTime);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         aFriendCollection.FriendList.ForEach(vFriend =>
         {
             vSqlCommand.Parameters["@FAN1Key"].Value = vFriend.Fan1Key;
             vSqlCommand.Parameters["@FAN2Key"].Value = vFriend.Fan2Key;
             vSqlCommand.Parameters["@RELKey"].Value = vFriend.Relationship;
             vSqlCommand.Parameters["@FRDDateEstablished"].Value = vFriend.FriendDateEstablished;
             vSqlCommand.ExecuteScalar();
         });
         vSqlCommand.Connection.Close();
     }
 }
Exemplo n.º 8
0
 /// <summary>
 ///   Insert a <see cref="Friend"/> passed as an argument via Stored Procedure that returns the newly inserted Friend Key
 /// </summary>
 /// <param name="aFriend">A <see cref="Friend"/>.</param>
 /// <exception cref="ArgumentNullException">If <c>aFriend</c> argument is <c>null</c>.</exception>
 public static void Insert(FriendCollection aFriendCollection)
 {
     if (aFriendCollection == null)
     {
         throw new ArgumentNullException("aFriendCollection");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("insert into FRD_Friend");
         vStringBuilder.AppendLine("       (FAN_Key1, FAN_Key2,");
         vStringBuilder.AppendLine("        REL_Key,");
         vStringBuilder.AppendLine("        FRD_DateEstablished)");
         vStringBuilder.AppendLine("values");
         vStringBuilder.AppendLine("       (@FAN1Key, @FAN2Key,");
         vStringBuilder.AppendLine("        @RELKey, @FRDDateEstablished)");
         vStringBuilder.AppendLine(";");
         vSqlCommand.Parameters.Add("@FAN1Key", SqlDbType.Int);
         vSqlCommand.Parameters.Add("@FAN2Key", SqlDbType.Int);
         vSqlCommand.Parameters.Add("@RELKey", SqlDbType.Int);
         vSqlCommand.Parameters.Add("@FRDDateEstablished", SqlDbType.DateTime);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         aFriendCollection.FriendList.ForEach(vFriend =>
         {
             vSqlCommand.Parameters["@FAN1Key"].Value            = vFriend.Fan1Key;
             vSqlCommand.Parameters["@FAN2Key"].Value            = vFriend.Fan2Key;
             vSqlCommand.Parameters["@RELKey"].Value             = vFriend.Relationship;
             vSqlCommand.Parameters["@FRDDateEstablished"].Value = vFriend.FriendDateEstablished;
             vSqlCommand.ExecuteScalar();
         });
         vSqlCommand.Connection.Close();
     }
 }
Exemplo n.º 9
0
 public static void Save(FriendCollection aFriendCollection)
 {
     Delete(aFriendCollection.FriendFilter.FriendshipFilter);
     Insert(aFriendCollection);
 }
Exemplo n.º 10
0
 /// <summary>
 ///   The overloaded Load method that will fill the <c>FriendList</c> property a <see cref="FriendCollection"/> object as an
 ///   ordered <c>List</c> of <see cref="Friend"/>, filtered by the filter properties of the passed <see cref="FriendCollection"/>.
 /// </summary>
 /// <param name="aFriendCollection">The <see cref="FriendCollection"/> object that must be filled.</param>
 /// <remarks>
 ///   The filter properties of the <see cref="FriendCollection"/> must be correctly completed by the calling application.
 /// </remarks>
 /// <exception cref="ArgumentNullException">If <c>aFriendCollection</c> argument is <c>null</c>.</exception>
 public static void Load(FriendCollection aFriendCollection)
 {
     if (aFriendCollection == null)
     {
         throw new ArgumentNullException("aFriendCollection");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = BuildSQL();
         if (aFriendCollection.IsFiltered)
         {
             if (aFriendCollection.FriendFilter.FriendshipFilter.Fan1Key > 0)
             {
                 vStringBuilder.AppendLine("and (t1.FAN_Key = @FAN1Key or t2.FAN_Key = @FAN1Key)");
                 vSqlCommand.Parameters.AddWithValue("@FAN1Key", aFriendCollection.FriendFilter.FriendshipFilter.Fan1Key);
             }
             if (aFriendCollection.FriendFilter.FriendshipFilter.Fan2Key > 0)
             {
                 vStringBuilder.AppendLine("and (t2.FAN_Key = @FAN2Key or t2.FAN_Key = @FAN2Key)");
                 vSqlCommand.Parameters.AddWithValue("@FAN2Key", aFriendCollection.FriendFilter.FriendshipFilter.Fan2Key);
             }
             if (aFriendCollection.FriendFilter.FriendshipFilter.Fan1Name != null)
             {
                 vStringBuilder.AppendFormat("and (t1.FAN_Name like '%{0}%' or t2.FAN_Name like '%{0}%')", aFriendCollection.FriendFilter.FriendshipFilter.Fan1Name);
             }
             if (aFriendCollection.FriendFilter.FriendshipFilter.Fan2Name != null)
             {
                 vStringBuilder.AppendFormat("and (t1.FAN_Name like '%{0}%' or t2.FAN_Name like '%{0}%')", aFriendCollection.FriendFilter.FriendshipFilter.Fan2Name);
             }
         }
         vStringBuilder.AppendLine("order by t3.FRD_DateEstablished");
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader())
         {
             while (vSqlDataReader.Read())
             {
                 var vFriend = new Friend();
                 DataToObject(vFriend, vSqlDataReader, false);
                 aFriendCollection.FriendList.Add(vFriend);
             }
             vSqlDataReader.Close();
         }
         vSqlCommand.Connection.Close();
     }
 }
Exemplo n.º 11
0
 /// <summary>
 /// Add a <see cref="Friend" />.
 /// </summary>
 /// <param name="aFanToken">A <see cref="FanToken" /> object used for Access Control.</param>
 /// <param name="aFriendCollection">A provider suburb collection.</param>
 public static void SaveFriend(FanToken aFanToken, FriendCollection aFriendCollection)
 {
     FanCallHandler.ServiceCall <FriendCollection>(aFanToken, "SaveFriend", aFriendCollection);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Add a <see cref="Friend" />.
 /// </summary>
 /// <param name="aFanToken">A <see cref="FanToken" /> object used for Access Control.</param>
 /// <param name="aFriendCollection">A provider suburb collection.</param>
 public static void SaveFriend(FanToken aFanToken, FriendCollection aFriendCollection)
 {
     FanCallHandler.ServiceCall<FriendCollection>(aFanToken, "SaveFriend", aFriendCollection);
 }
Exemplo n.º 13
0
 public static void Save(FriendCollection aFriendCollection)
 {
     Delete(aFriendCollection.FriendFilter.FriendshipFilter);
     Insert(aFriendCollection);
 }
Exemplo n.º 14
0
        public static webObject loadFriendCollection(FriendCollection aFriendCollection)
        {
            FanToken vFanToken = ServerSession.GetFanToken(HttpContext.Current.Session);
            ServerSession.ClearSessionBusiness(HttpContext.Current.Session);
            webObject vWebObject = new webObject();
            vWebObject.aTransactionStatus = ServerSession.GetTransactionStatus(HttpContext.Current.Session);

            try
            {
                FanServiceConsumer.GetFriendCollection(vFanToken, aFriendCollection);
                vWebObject.aTransactionStatus.TransactionResult = TransactionResult.OK;
                vWebObject.aTransactionStatus.Message = "FriendCollection Loaded";
                ServerSession.SetTransactionStatus(HttpContext.Current.Session, vWebObject.aTransactionStatus);
                vWebObject.AnObject = aFriendCollection;
            }
            catch (TransactionStatusException tx)
            {
                vWebObject.aTransactionStatus.AssignFromSource(tx.TransactionStatus);
                return vWebObject;
            }
            catch (Exception ex)
            {
                vWebObject.aTransactionStatus.TransactionResult = TransactionResult.GeneralException;
                vWebObject.aTransactionStatus.Message = "Load of FriendCollection unsuccesful" + ex.Message;
                vWebObject.aTransactionStatus.InnerMessage = ex.InnerException == null ? String.Empty : ex.InnerException.Message;
                return vWebObject;
            }
            return vWebObject;
        }
Exemplo n.º 15
0
 /// <summary>
 /// Saves the provider suburb.
 /// </summary>
 /// <param name="aFanKey">A user key.</param>
 /// <param name="aXmlArgument">A XML argument.</param>
 /// <returns>A string of XML representing a FriendCollection</returns>
 /// <exception cref="System.ArgumentNullException">aXmlArgument of SaveFriend</exception>
 public static string SaveFriend(FanKey aFanKey, string aXmlArgument)
 {
     if (aXmlArgument == null)
     {
         throw new ArgumentNullException("aXmlArgument of SaveFriend");
     }
     FriendCollection vFriendCollection = new FriendCollection();
     vFriendCollection = XmlUtils.Deserialize<FriendCollection>(aXmlArgument);
     FriendBusiness.Save(aFanKey, vFriendCollection);
     return XmlUtils.Serialize<FriendCollection>(vFriendCollection, true);
 }
Exemplo n.º 16
0
 /// <summary>
 ///   Gets a specified <see cref="FriendCollection"/>.
 /// </summary>
 /// <param name="aFanToken">A <see cref="FanToken"/> object used for Access Control.</param>
 /// <param name="aFriendCollection"><see cref="Friend"/>Collection object.</param>
 public static void GetFriendCollection(FanToken aFanToken, FriendCollection aFriendCollection)
 {
     FanCallHandler.ServiceCall <FriendCollection>(aFanToken, "GetFriendCollection", aFriendCollection);
 }
Exemplo n.º 17
0
 /// <summary>
 ///   Gets a specified <see cref="FriendCollection"/>.
 /// </summary>
 /// <param name="aFanToken">A <see cref="FanToken"/> object used for Access Control.</param>
 /// <param name="aFriendCollection"><see cref="Friend"/>Collection object.</param>
 public static void GetFriendCollection(FanToken aFanToken, FriendCollection aFriendCollection)
 {
     FanCallHandler.ServiceCall<FriendCollection>(aFanToken, "GetFriendCollection", aFriendCollection);
 }