示例#1
0
 /// <summary>
 ///   Insert a <see cref="Contributor"/> passed as an argument via Stored Procedure that returns the newly inserted Contributor Key 
 /// </summary>
 /// <param name="aContributor">A <see cref="Contributor"/>.</param>
 /// <exception cref="ArgumentNullException">If <c>aContributor</c> argument is <c>null</c>.</exception>
 public static void Insert(Contributor aContributor)
 {
     if (aContributor == null)
     {
         throw new ArgumentNullException("aContributor");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("insert into CON_Contributor");
         vStringBuilder.AppendLine("       (CON_Name, CON_Surname, CON_Contact, CON_Email, CON_Avatar, CON_Password)");
         vStringBuilder.AppendLine("values");
         vStringBuilder.AppendLine("       (@CONName, @CONSurname, @CONContact, @CONEmail, @CONAvatar, @CONPassword)");
         vStringBuilder.AppendLine(";");
         vStringBuilder.AppendLine("select SCOPE_IDENTITY()");
         ObjectToData(vSqlCommand, aContributor);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         aContributor.ConKey = Convert.ToInt32(vSqlCommand.ExecuteScalar());
         vSqlCommand.Connection.Close();
     }
 }
示例#2
0
 /// <summary>
 ///   The <c>AddContributor</c> implementation method deserializes an incoming XML Argument <see cref="string"/> as a new <see cref="Contributor"/> object.
 ///   It invokes the <c>Insert</c> method of <see cref="ContributorBusiness"/> with the newly deserialized <see cref="Contributor"/> object.
 ///   Finally, it returns the inserted object (now with an assigned Contributor Key) as a serialized <see cref="string"/> of XML.
 /// </summary>
 /// <param name="aXmlArgument">XML Argument <see cref="string"/>.</param>
 /// <returns><see cref="Contributor"/> as XML <see cref="string"/>.</returns>
 /// <exception cref="ArgumentNullException">If <c>aXmlArgument</c> is <c>null</c>.</exception>
 public static string AddContributor(UserKey aUserKey, string aXmlArgument)
 {
     if (aXmlArgument == null)
     {
         throw new ArgumentNullException("aXmlArgument of AddContributor");
     }
     Contributor vContributor = new Contributor();
     vContributor = XmlUtils.Deserialize<Contributor>(aXmlArgument);
     ContributorBusiness.Insert(aUserKey, vContributor);
     return XmlUtils.Serialize<Contributor>(vContributor, true);
 }
示例#3
0
 /// <summary>
 ///   Load a <see cref="SqlDataReader"/> into a <see cref="Contributor"/> object.
 /// </summary>
 /// <param name="aContributor">A <see cref="Contributor"/> argument.</param>
 /// <param name="aSqlDataReader">A <see cref="SqlDataReader"/> argument.</param>
 public static void DataToObject(Contributor aContributor, SqlDataReader aSqlDataReader, bool aIncludeAvatar)
 {
     aContributor.ConKey = Convert.ToInt32(aSqlDataReader["CON_Key"]);
     aContributor.ConName = Convert.ToString(aSqlDataReader["CON_Name"]);
     aContributor.ConSurname = Convert.ToString(aSqlDataReader["CON_Surname"]);
     aContributor.ConEmail = Convert.ToString(aSqlDataReader["CON_Email"]);
     aContributor.ConPassword = Convert.ToString(aSqlDataReader["CON_Password"]);
     aContributor.ConContact = Convert.ToString(aSqlDataReader["CON_Contact"]);
     if (aIncludeAvatar)
     {
         aContributor.ConAvatar = CommonUtils.DbValueTo<byte[]>(aSqlDataReader["CON_Avatar"], null);
     }
 }
示例#4
0
        /// <summary>
        ///   The overloaded Load method that will return a specific <see cref="Contributor"/> object, with keys in <c>aContributor</c>.
        /// </summary>
        /// <param name="aUserKey">A <see cref="UserKey"/> object.</param>
        /// <param name="aContributor">A <see cref="Contributor"/>.</param>
        /// <exception cref="ArgumentNullException">If <c>aContributor</c> is <c>null</c>.</exception>
        public static void Load(UserKey aUserKey, Contributor aContributor)
        {
            if (aContributor == null)
            {
                throw new ArgumentNullException("Load Contributor Business");
            }

            if (!UserFunctionAccessData.HasModeAccess(aUserKey, "Contributor", AccessMode.Read))
            {
                throw new ZpAccessException("Access Denied", String.Format("{0}", aUserKey.UsrKey), AccessMode.Read, "Contributor");
            }

            ContributorData.Load(aContributor);
        }
示例#5
0
        /// <summary>
        ///    Assigns all <c>aSource</c> object's values to this instance of <see cref="ContributorCollection"/>.
        /// </summary>
        /// <param name="aSource">A source object.</param>
        public override void AssignFromSource(object aSource)
        {
            if (!(aSource is ContributorCollection))
            {
                throw new ArgumentException("Invalid assignment source", "ContributorCollection");
            }

            _contributorFilter.AssignFromSource((aSource as ContributorCollection)._contributorFilter);
            _contributorList.Clear();
            (aSource as ContributorCollection)._contributorList.ForEach(vContributorSource =>
            {
                Contributor vContributorTarget = new Contributor();
                vContributorTarget.AssignFromSource(vContributorSource);
                _contributorList.Add(vContributorTarget);
            });
        }
示例#6
0
 /// <summary>
 ///   Delete a <see cref="Advertiser"/> object passed as an argument.
 /// </summary>
 /// <param name="aAdvertiser">The <see cref="Advertiser"/> object to be deleted.</param>
 /// <exception cref="ArgumentNullException">If <c>aAdvertiser</c> argument is <c>null</c>.</exception>
 public static void Delete(Contributor aContributor)
 {
     if (aContributor == null)
     {
         throw new ArgumentNullException("aContributor");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("delete CON_Contributor");
         vStringBuilder.AppendLine("where  CON_Key = @CONKey");
         vSqlCommand.Parameters.AddWithValue("@CONKey", aContributor.ConKey);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         vSqlCommand.ExecuteNonQuery();
         vSqlCommand.Connection.Close();
     }
 }
示例#7
0
 /// <summary>
 ///   Gets a specified <see cref="Contributor"/> by key.
 /// </summary>
 /// <param name="aUserToken">A <see cref="UserToken"/> object used for Access Control.</param>
 /// <param name="aContributor"><see cref="Contributor"/> object.</param>
 public static void GetContributor(UserToken aUserToken, Contributor aContributor)
 {
     UserCallHandler.ServiceCall<Contributor>(aUserToken, "GetContributor", aContributor);
 }
示例#8
0
 /// <summary>
 ///   Update a <see cref="Contributor"/> passed as an argument .
 /// </summary>
 /// <param name="aContributor">A <see cref="Contributor"/>.</param>
 public static void Update(Contributor aContributor)
 {
     if (aContributor == null)
     {
         throw new ArgumentNullException("aContributor");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("update CON_Contributor");
         vStringBuilder.AppendLine("set    CON_Name = @CONName,");
         vStringBuilder.AppendLine("       CON_Surname = @CONSurname,");
         vStringBuilder.AppendLine("       CON_Contact = @CONContact,");
         vStringBuilder.AppendLine("       CON_Email = @CONEmail");
         vStringBuilder.AppendLine("where  CON_Key = @CONKey");
         ObjectToData(vSqlCommand, aContributor);
         vSqlCommand.Parameters.AddWithValue("@CONKey", aContributor.ConKey);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         vSqlCommand.ExecuteNonQuery();
         vSqlCommand.Connection.Close();
     }
 }
示例#9
0
 /// <summary>
 ///   Loads the <see cref="SqlCommand"/> parameters with values from an <see cref="Contributor"/>.
 /// </summary>
 /// <param name="aSqlCommand">A <see cref="SqlDataReader"/> argument.</param>
 /// <param name="aContributor">A <see cref="Contributor"/> argument.</param>
 public static void ObjectToData(SqlCommand aSqlCommand, Contributor aContributor)
 {
     aSqlCommand.Parameters.AddWithValue("@CONName", aContributor.ConName);
     aSqlCommand.Parameters.AddWithValue("@CONSurname", aContributor.ConSurname);
     aSqlCommand.Parameters.AddWithValue("@CONEmail", aContributor.ConEmail);
     aSqlCommand.Parameters.AddWithValue("@CONContact", aContributor.ConContact);
     aSqlCommand.Parameters.AddWithValue("@CONPassword", aContributor.ConPassword);
     if (aContributor.ConAvatar == null)
     {
         aSqlCommand.Parameters.Add("@CONAvatar", SqlDbType.Image).Value = DBNull.Value;
     }
     else
     {
         aSqlCommand.Parameters.AddWithValue("@CONAvatar", aContributor.ConAvatar);
     }
 }
示例#10
0
 /// <summary>
 ///   The overloaded Load method that will return a specific <see cref="Contributor"/>, with keys in the <c>aContributor</c> argument.
 /// </summary>
 /// <param name="aContributor">A <see cref="Contributor"/>.</param>
 /// <exception cref="ArgumentNullException">If <c>aContributor</c> argument is <c>null</c>.</exception>
 /// <exception cref="Exception">If no record is found.</exception>
 public static void Load(Contributor aContributor)
 {
     if (aContributor == null)
     {
         throw new ArgumentNullException("aContributor");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = BuildSQL();
         vStringBuilder.AppendLine("where    t1.CON_Key = @CONKey");
         vSqlCommand.Parameters.AddWithValue("@CONKey", aContributor.ConKey);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader())
         {
             if (!vSqlDataReader.HasRows)
             {
                 throw new Exception(String.Format("Expected Contributor not found: CON_Key = {0}", aContributor.ConKey));
             }
             vSqlDataReader.Read();
             DataToObject(aContributor, vSqlDataReader, false);
             vSqlDataReader.Close();
         }
         vSqlCommand.Connection.Close();
     }
 }
示例#11
0
 /// <summary>
 ///   The overloaded Load method that will fill the <c>ContributorList</c> property a <see cref="ContributorCollection"/> object as an
 ///   ordered <c>List</c> of <see cref="Contributor"/>, filtered by the filter properties of the passed <see cref="ContributorCollection"/>.
 /// </summary>
 /// <param name="aContributorCollection">The <see cref="ContributorCollection"/> object that must be filled.</param>
 /// <remarks>
 ///   The filter properties of the <see cref="ContributorCollection"/> must be correctly completed by the calling application.
 /// </remarks>
 /// <exception cref="ArgumentNullException">If <c>aContributorCollection</c> argument is <c>null</c>.</exception>
 public static void Load(ContributorCollection aContributorCollection)
 {
     if (aContributorCollection == null)
     {
         throw new ArgumentNullException("aContributorCollection");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = BuildSQL();
         if (aContributorCollection.ContributorFilter.IsFiltered)
         {
             vStringBuilder.AppendLine("     , CTL_ContributorLanguage t2");
             vStringBuilder.AppendLine("where  t1.CON_Key = t2.CON_Key");
             vStringBuilder.AppendLine("and    t2.LAN_Key = @LANKEY");
             vStringBuilder.AppendLine("and    t2.CTL_Rating >= @CTLRating");
             vSqlCommand.Parameters.AddWithValue("@LANKEY", aContributorCollection.ContributorFilter.LanguageFilter);
             vSqlCommand.Parameters.AddWithValue("@CTLRating", aContributorCollection.ContributorFilter.RatingFilter);
             vStringBuilder.AppendLine("order by t2.CTL_Rating");
         }
         else
         {
             vStringBuilder.AppendLine("order by t1.CON_Surname");
         }
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader())
         {
             while (vSqlDataReader.Read())
             {
                 var vContributor = new Contributor();
                 DataToObject(vContributor, vSqlDataReader, false);
                 aContributorCollection.ContributorList.Add(vContributor);
             }
             vSqlDataReader.Close();
         }
         vSqlCommand.Connection.Close();
     }
 }