示例#1
0
 /// <summary>
 ///   Insert a <see cref="Exercise"/> passed as an argument via Stored Procedure that returns the newly inserted Exercise Key 
 /// </summary>
 /// <param name="aExercise">A <see cref="Exercise"/>.</param>
 /// <exception cref="ArgumentNullException">If <c>aExercise</c> argument is <c>null</c>.</exception>
 public static void Insert(Exercise aExercise)
 {
     if (aExercise == null)
     {
         throw new ArgumentNullException("aExercise");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("insert into EXC_Exercise");
         vStringBuilder.AppendLine("       (EXC_Name,");
         vStringBuilder.AppendLine("        EXC_Type)");
         vStringBuilder.AppendLine("values");
         vStringBuilder.AppendLine("       (@EXCName,");
         vStringBuilder.AppendLine("        @EXCType)");
         vStringBuilder.AppendLine(";");
         vStringBuilder.AppendLine("select SCOPE_IDENTITY()");
         ObjectToData(vSqlCommand, aExercise);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         aExercise.ExcKey = Convert.ToInt32(vSqlCommand.ExecuteScalar());
         vSqlCommand.Connection.Close();
     }
 }
示例#2
0
        public static webObject addExercise(Exercise aExercise)
        {
            FanToken vFanToken = ServerSession.GetFanToken(HttpContext.Current.Session);
            webObject vWebObject = new webObject();
            vWebObject.aTransactionStatus = ServerSession.GetTransactionStatus(HttpContext.Current.Session);

            try
            {
                FanServiceConsumer.AddExercise(vFanToken, aExercise);
                vWebObject.aTransactionStatus.TransactionResult = TransactionResult.OK;
                vWebObject.aTransactionStatus.Message = "Exercise Added";
                ServerSession.SetTransactionStatus(HttpContext.Current.Session, vWebObject.aTransactionStatus);
                vWebObject.AnObject = aExercise;
            }
            catch (TransactionStatusException tx)
            {

                vWebObject.aTransactionStatus.AssignFromSource(tx.TransactionStatus);
                return vWebObject;
            }
            catch (Exception ex)
            {
                vWebObject.aTransactionStatus.TransactionResult = TransactionResult.GeneralException;
                vWebObject.aTransactionStatus.Message = "Addition of Exercise unsuccesful" + ex.Message;
                vWebObject.aTransactionStatus.InnerMessage = ex.InnerException == null ? String.Empty : ex.InnerException.Message;
                return vWebObject;
            }
            return vWebObject;
        }
示例#3
0
 /// <summary>
 ///   The <c>AddExercise</c> implementation method deserializes an incoming XML Argument <see cref="string"/> as a new <see cref="Exercise"/> object.
 ///   It invokes the <c>Insert</c> method of <see cref="ExerciseBusiness"/> with the newly deserialized <see cref="Exercise"/> object.
 ///   Finally, it returns the inserted object (now with an assigned Exercise Key) as a serialized <see cref="string"/> of XML.
 /// </summary>
 /// <param name="aXmlArgument">XML Argument <see cref="string"/>.</param>
 /// <returns><see cref="Exercise"/> as XML <see cref="string"/>.</returns>
 /// <exception cref="ArgumentNullException">If <c>aXmlArgument</c> is <c>null</c>.</exception>
 public static string AddExercise(FanKey aFanKey, string aXmlArgument)
 {
     if (aXmlArgument == null)
     {
         throw new ArgumentNullException("aXmlArgument of AddExercise");
     }
     Exercise vExercise = new Exercise();
     vExercise = XmlUtils.Deserialize<Exercise>(aXmlArgument);
     ExerciseBusiness.Insert(aFanKey, vExercise);
     return XmlUtils.Serialize<Exercise>(vExercise, true);
 }
示例#4
0
        /// <summary>
        ///   The overloaded Load method that will return a specific <see cref="Exercise"/> object, with keys in <c>aExercise</c>.
        /// </summary>
        /// <param name="aFanKey">A <see cref="FanKey"/> object.</param>
        /// <param name="aExercise">A <see cref="Exercise"/>.</param>
        /// <exception cref="ArgumentNullException">If <c>aExercise</c> is <c>null</c>.</exception>
        public static void Load(FanKey aFanKey, Exercise aExercise)
        {
            if (aExercise == null)
            {
                throw new ArgumentNullException("Load Exercise Business");
            }

            //if (!FanFunctionAccessData.HasModeAccess(aFanKey, "Exercise", AccessMode.Read))
            //{
            //    throw new ZpAccessException("Access Denied", String.Format("{0}", aFanKey.ExercisenKey), AccessMode.Read, "Exercise");
            //}

            ExerciseData.Load(aExercise);
        }
示例#5
0
        /// <summary>
        ///   Insert a <see cref="Exercise"/> object passed as an argument via Stored Procedure that returns the newly inserted <i>Exercise Key</i>.
        /// </summary>
        /// <param name="aFanKey">A <see cref="FanKey"/> object.</param>
        /// <param name="aExercise">A <see cref="Exercise"/> object.</param>
        /// <exception cref="ArgumentNullException">If <c>aExercise</c> argument is <c>null</c>.</exception>
        public static void Insert(FanKey aFanKey, Exercise aExercise)
        {
            if (aExercise == null)
            {
                throw new ArgumentNullException("Insert Exercise Business");
            }

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

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

            _isFiltered = (aSource as ExerciseCollection)._isFiltered;
            _exerciseFilter = (aSource as ExerciseCollection)._exerciseFilter;
            _exerciseList.Clear();
            foreach (Exercise vExerciseSource in (aSource as ExerciseCollection)._exerciseList)
            {
                Exercise vExerciseTarget = new Exercise();
                vExerciseTarget.AssignFromSource(vExerciseSource);
                _exerciseList.Add(vExerciseTarget);
            }
        }
示例#7
0
 /// <summary>
 ///   Delete a <see cref="Exercise"/> object passed as an argument.
 /// </summary>
 /// <param name="aExercise">The <see cref="Exercise"/> object to be deleted.</param>
 /// <exception cref="ArgumentNullException">If <c>aExercise</c> argument is <c>null</c>.</exception>
 public static void Delete(Exercise aExercise)
 {
     if (aExercise == null)
     {
         throw new ArgumentNullException("aExercise");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("delete EXC_Exercise");
         vStringBuilder.AppendLine("where  EXC_Key = @EXCKey");
         vSqlCommand.Parameters.AddWithValue("@EXCKey", aExercise.ExcKey);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         vSqlCommand.ExecuteNonQuery();
         vSqlCommand.Connection.Close();
     }
 }
示例#8
0
 /// <summary>
 ///   The overloaded Load method that will fill the <c>ExerciseList</c> property a <see cref="ExerciseCollection"/> object as an
 ///   ordered <c>List</c> of <see cref="Exercise"/>, filtered by the filter properties of the passed <see cref="ExerciseCollection"/>.
 /// </summary>
 /// <param name="aExerciseCollection">The <see cref="ExerciseCollection"/> object that must be filled.</param>
 /// <remarks>
 ///   The filter properties of the <see cref="ExerciseCollection"/> must be correctly completed by the calling application.
 /// </remarks>
 /// <exception cref="ArgumentNullException">If <c>aExerciseCollection</c> argument is <c>null</c>.</exception>
 public static void Load(ExerciseCollection aExerciseCollection)
 {
     if (aExerciseCollection == null)
     {
         throw new ArgumentNullException("aExerciseCollection");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = BuildSQL();
         if (aExerciseCollection.IsFiltered)
         {
             vStringBuilder.AppendFormat("where t1.EXC_Name is like '%{0}%", aExerciseCollection.ExerciseFilter.ExcFilter.ExcName);
         }
         vStringBuilder.AppendLine("order by t1.EXC_Name");
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader())
         {
             while (vSqlDataReader.Read())
             {
                 var vExercise = new Exercise();
                 DataToObject(vExercise, vSqlDataReader);
                 aExerciseCollection.ExerciseList.Add(vExercise);
             }
             vSqlDataReader.Close();
         }
         vSqlCommand.Connection.Close();
     }
 }
示例#9
0
 /// <summary>
 ///   Load a <see cref="SqlDataReader"/> into a <see cref="Exercise"/> object.
 /// </summary>
 /// <param name="aExercise">A <see cref="Exercise"/> argument.</param>
 /// <param name="aSqlDataReader">A <see cref="SqlDataReader"/> argument.</param>
 public static void DataToObject(Exercise aExercise, SqlDataReader aSqlDataReader)
 {
     aExercise.ExcKey = Convert.ToInt32(aSqlDataReader["EXC_Key"]);
     aExercise.ExcName = Convert.ToString(aSqlDataReader["EXC_Name"]);
     aExercise.ExcType = Convert.ToInt32(aSqlDataReader["EXC_Key"]);
 }
示例#10
0
 /// <summary>
 ///   Loads the <see cref="SqlCommand"/> parameters with values from an <see cref="Exercise"/>.
 /// </summary>
 /// <param name="aSqlCommand">A <see cref="SqlDataReader"/> argument.</param>
 /// <param name="aExercise">A <see cref="Exercise"/> argument.</param>
 public static void ObjectToData(SqlCommand aSqlCommand, Exercise aExercise)
 {
     aSqlCommand.Parameters.AddWithValue("@EXCName", aExercise.ExcName);
     aSqlCommand.Parameters.AddWithValue("@EXCType", aExercise.ExcType);
 }
示例#11
0
 /// <summary>
 ///   The overloaded Load method that will return a specific <see cref="Exercise"/>, with keys in the <c>aExercise</c> argument.
 /// </summary>
 /// <param name="aExercise">A <see cref="Exercise"/>.</param>
 /// <exception cref="ArgumentNullException">If <c>aExercise</c> argument is <c>null</c>.</exception>
 /// <exception cref="Exception">If no record is found.</exception>
 public static void Load(Exercise aExercise)
 {
     if (aExercise == null)
     {
         throw new ArgumentNullException("aExercise");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = BuildSQL();
         vStringBuilder.AppendLine("where t1.EXC_Key = @EXCKey");
         vSqlCommand.Parameters.AddWithValue("@EXCKey", aExercise.ExcKey);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader())
         {
             if (!vSqlDataReader.HasRows)
             {
                 throw new Exception(String.Format("Expected Exercise not found: EXC_Key = {0}", aExercise.ExcKey));
             }
             vSqlDataReader.Read();
             DataToObject(aExercise, vSqlDataReader);
             vSqlDataReader.Close();
         }
         vSqlCommand.Connection.Close();
     }
 }
示例#12
0
        public static webObject loadExerciseCollection(Exercise aExercise)
        {
            ExerciseCollection vExerciseCollection = new ExerciseCollection();
            vExerciseCollection.ExerciseFilter.ExcFilter.AssignFromSource(aExercise);

            FanToken vFanToken = ServerSession.GetFanToken(HttpContext.Current.Session);
            webObject vWebObject = new webObject();
            vWebObject.aTransactionStatus = ServerSession.GetTransactionStatus(HttpContext.Current.Session);

            try
            {
                FanServiceConsumer.GetExerciseCollection(vFanToken, vExerciseCollection);
                vWebObject.aTransactionStatus.TransactionResult = TransactionResult.OK;
                vWebObject.aTransactionStatus.Message = "ExerciseCollection Loaded";
                ServerSession.SetTransactionStatus(HttpContext.Current.Session, vWebObject.aTransactionStatus);
                vWebObject.AnObject = vExerciseCollection;
            }
            catch (TransactionStatusException tx)
            {

                vWebObject.aTransactionStatus.AssignFromSource(tx.TransactionStatus);
                return vWebObject;
            }
            catch (Exception ex)
            {
                vWebObject.aTransactionStatus.TransactionResult = TransactionResult.GeneralException;
                vWebObject.aTransactionStatus.Message = "Load of ExerciseCollection unsuccesful" + ex.Message;
                vWebObject.aTransactionStatus.InnerMessage = ex.InnerException == null ? String.Empty : ex.InnerException.Message;
                return vWebObject;
            }
            return vWebObject;
        }
示例#13
0
 /// <summary>
 /// Call the WebService with a request to Add a Exercise
 /// </summary>
 /// <param name="aExercise">The Exercise object to Add</param>
 /// <param name="aFantoken">A fantoken.</param>
 public static void AddExercise(FanToken aFantoken, Exercise aExercise)
 {
     FanCallHandler.ServiceCall<Exercise>(aFantoken, "AddExercise", aExercise);
 }