Exemple #1
0
        /// <summary>
        ///   The overloaded Load method that will return a specific <see cref="Workout"/> object, with keys in <c>aWorkout</c>.
        /// </summary>
        /// <param name="aFanKey">A <see cref="FanKey"/> object.</param>
        /// <param name="aWorkout">A <see cref="Workout"/>.</param>
        /// <exception cref="ArgumentNullException">If <c>aWorkout</c> is <c>null</c>.</exception>
        public static void Load(FanKey aFanKey, Workout aWorkout)
        {
            if (aWorkout == null)
            {
                throw new ArgumentNullException("Load Workout Business");
            }

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

            WorkoutData.Load(aWorkout);
        }
Exemple #2
0
 /// <summary>
 ///   Load a <see cref="SqlDataReader"/> into a <see cref="Workout"/> object.
 /// </summary>
 /// <param name="aWorkout">A <see cref="Workout"/> argument.</param>
 /// <param name="aSqlDataReader">A <see cref="SqlDataReader"/> argument.</param>
 public static void DataToObject(Workout aWorkout, SqlDataReader aSqlDataReader)
 {
     aWorkout.WrtKey = Convert.ToInt32(aSqlDataReader["WRT_Key"]);
     aWorkout.WrtName = Convert.ToString(aSqlDataReader["WRT_Name"]);
     aWorkout.WrtAvailability = Convert.ToInt32(aSqlDataReader["WRT_Availability"]);
     aWorkout.WrtDescription = Convert.ToString(aSqlDataReader["WRT_Description"]);
     aWorkout.WrtOwnerKey = Convert.ToInt32(aSqlDataReader["FAN_Key"]);
     aWorkout.WrtOwnerName = string.Format("{0} {1}", Convert.ToString(aSqlDataReader["FAN_Name"]), Convert.ToString(aSqlDataReader["FAN_Surname"]));
     aWorkout.WrtResultFunction = Convert.ToString(aSqlDataReader["WRT_ResultFunction"]);
     aWorkout.CelKey = Convert.ToInt32(aSqlDataReader["CEL_Key"]);
     aWorkout.CelName = Convert.ToString(aSqlDataReader["CEL_Name"]);
     aWorkout.FedKey = Convert.ToInt32(aSqlDataReader["FED_Key"]);
     aWorkout.FedName = Convert.ToString(aSqlDataReader["FED_Name"]);
     aWorkout.DateCreated = (Convert.ToDateTime(aSqlDataReader["WRT_Date"])).ToLongDateString();
 }
Exemple #3
0
        /// <summary>
        ///   Insert a <see cref="Workout"/> object passed as an argument via Stored Procedure that returns the newly inserted <i>Workout Key</i>.
        /// </summary>
        /// <param name="aFanKey">A <see cref="FanKey"/> object.</param>
        /// <param name="aWorkout">A <see cref="Workout"/> object.</param>
        /// <exception cref="ArgumentNullException">If <c>aWorkout</c> argument is <c>null</c>.</exception>
        public static void Insert(FanKey aFanKey, Workout aWorkout)
        {
            if (aWorkout == null)
            {
                throw new ArgumentNullException("Insert Workout Business");
            }

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

            //Set date of creation before insert
            aWorkout.DateCreated = DateTime.Now.ToLongDateString();
            WorkoutData.Insert(aWorkout);
        }
        /// <summary>
        ///    Assigns all <c>aSource</c> object's values to this instance of <see cref="WorkoutCollection"/>.
        /// </summary>
        /// <param name="aSource">A source object.</param>
        public override void AssignFromSource(object aSource)
        {
            if (!(aSource is WorkoutCollection))
            {
                throw new ArgumentException("Invalid assignment source", "WorkoutCollection");
            }

            _isFiltered = (aSource as WorkoutCollection)._isFiltered;
            _workoutFilter = (aSource as WorkoutCollection)._workoutFilter;
            _workoutList.Clear();
            foreach (Workout vWorkoutSource in (aSource as WorkoutCollection)._workoutList)
            {
                Workout vWorkoutTarget = new Workout();
                vWorkoutTarget.AssignFromSource(vWorkoutSource);
                _workoutList.Add(vWorkoutTarget);
            }
        }
Exemple #5
0
 /// <summary>
 ///   Insert a <see cref="Workout"/> passed as an argument via Stored Procedure that returns the newly inserted Workout Key 
 /// </summary>
 /// <param name="aWorkout">A <see cref="Workout"/>.</param>
 /// <exception cref="ArgumentNullException">If <c>aWorkout</c> argument is <c>null</c>.</exception>
 public static void Insert(Workout aWorkout)
 {
     if (aWorkout == null)
     {
         throw new ArgumentNullException("aWorkout");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("insert into WRT_Workout");
         vStringBuilder.AppendLine("       (WRT_Name,");
         vStringBuilder.AppendLine("        FAN_Key,");
         vStringBuilder.AppendLine("        WRT_Availability,");
         vStringBuilder.AppendLine("        FED_Key,");
         vStringBuilder.AppendLine("        CEL_Key,");
         vStringBuilder.AppendLine("        WRT_Date,");
         vStringBuilder.AppendLine("        WRT_ResultFunction,");
         vStringBuilder.AppendLine("        WRT_Description)");
         vStringBuilder.AppendLine("values");
         vStringBuilder.AppendLine("       (@WRTName,");
         vStringBuilder.AppendLine("        @WRTOwnerKey,");
         vStringBuilder.AppendLine("        @WRTAvailability,");
         vStringBuilder.AppendLine("        @WRTFedKey,");
         vStringBuilder.AppendLine("        @WRTCelKey,");
         vStringBuilder.AppendLine("        @WRTDateCreated,");
         vStringBuilder.AppendLine("        @WRTResultFunction,");
         vStringBuilder.AppendLine("        @WRTDescription)");
         vStringBuilder.AppendLine(";");
         vStringBuilder.AppendLine("select SCOPE_IDENTITY()");
         ObjectToData(vSqlCommand, aWorkout);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         aWorkout.WrtKey = Convert.ToInt32(vSqlCommand.ExecuteScalar());
         vSqlCommand.Connection.Close();
     }
 }
Exemple #6
0
 /// <summary>
 ///   Delete a <see cref="Workout"/> object passed as an argument.
 /// </summary>
 /// <param name="aWorkout">The <see cref="Workout"/> object to be deleted.</param>
 /// <exception cref="ArgumentNullException">If <c>aWorkout</c> argument is <c>null</c>.</exception>
 public static void Delete(Workout aWorkout)
 {
     if (aWorkout == null)
     {
         throw new ArgumentNullException("aWorkout");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("delete WRT_Workout");
         vStringBuilder.AppendLine("where  WRT_Key = @WRTKey");
         vSqlCommand.Parameters.AddWithValue("@WRTKey", aWorkout.WrtKey);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         vSqlCommand.ExecuteNonQuery();
         vSqlCommand.Connection.Close();
     }
 }
Exemple #7
0
        public static webObject loadWorkoutCollection(Workout aWorkout)
        {
            WorkoutCollection vWorkoutCollection = new WorkoutCollection();
            vWorkoutCollection.WorkoutFilter.WrtFilter.AssignFromSource(aWorkout);

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

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

                vWebObject.aTransactionStatus.AssignFromSource(tx.TransactionStatus);
                return vWebObject;
            }
            catch (Exception ex)
            {
                vWebObject.aTransactionStatus.TransactionResult = TransactionResult.GeneralException;
                vWebObject.aTransactionStatus.Message = "Load of WorkoutCollection unsuccesful" + ex.Message;
                vWebObject.aTransactionStatus.InnerMessage = ex.InnerException == null ? String.Empty : ex.InnerException.Message;
                return vWebObject;
            }
            return vWebObject;
        }
Exemple #8
0
        public static webObject editWorkout(Workout aWorkout)
        {
            FanToken vFanToken = ServerSession.GetFanToken(HttpContext.Current.Session);
            webObject vWebObject = new webObject();
            vWebObject.aTransactionStatus = ServerSession.GetTransactionStatus(HttpContext.Current.Session);

            try
            {
                FanServiceConsumer.EditWorkout(vFanToken, aWorkout);
                vWebObject.aTransactionStatus.TransactionResult = TransactionResult.OK;
                vWebObject.aTransactionStatus.Message = "Workout Edited";
                ServerSession.SetTransactionStatus(HttpContext.Current.Session, vWebObject.aTransactionStatus);
                vWebObject.AnObject = aWorkout;
            }
            catch (TransactionStatusException tx)
            {

                vWebObject.aTransactionStatus.AssignFromSource(tx.TransactionStatus);
                return vWebObject;
            }
            catch (Exception ex)
            {
                vWebObject.aTransactionStatus.TransactionResult = TransactionResult.GeneralException;
                vWebObject.aTransactionStatus.Message = "Edit of Workout unsuccesful" + ex.Message;
                vWebObject.aTransactionStatus.InnerMessage = ex.InnerException == null ? String.Empty : ex.InnerException.Message;
                return vWebObject;
            }
            return vWebObject;
        }
 /// <summary>
 ///   The <c>EditWorkout</c> implementation method deserializes an incoming XML Argument <see cref="string"/> as a new <see cref="Workout"/> object.
 ///   It invokes the <c>Update</c> method of <see cref="WorkoutBusiness"/> with the newly deserialized <see cref="Workout"/> object.
 ///   Finally, it returns the updated object unchanged as a serialized <see cref="string"/> of XML.
 /// </summary>
 /// <param name="aXmlArgument">XML Argument <see cref="string"/>.</param>
 /// <returns><see cref="Workout"/> as XML <see cref="string"/>.</returns>
 /// <exception cref="ArgumentNullException">If <c>aXmlArgument</c> is <c>null</c>.</exception>
 public static string EditWorkout(FanKey aFanKey, string aXmlArgument)
 {
     if (aXmlArgument == null)
     {
         throw new ArgumentNullException("aXmlArgument of EditWorkout");
     }
     Workout vWorkout = new Workout();
     vWorkout = XmlUtils.Deserialize<Workout>(aXmlArgument);
     WorkoutBusiness.Update(aFanKey, vWorkout);
     return XmlUtils.Serialize<Workout>(vWorkout, true);
 }
Exemple #10
0
 /// <summary>
 ///   Update a <see cref="Workout"/> passed as an argument .
 /// </summary>
 /// <param name="aWorkout">A <see cref="Workout"/>.</param>
 public static void Update(Workout aWorkout)
 {
     if (aWorkout == null)
     {
         throw new ArgumentNullException("aWorkout");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = new StringBuilder();
         vStringBuilder.AppendLine("update WRT_Workout");
         vStringBuilder.AppendLine("set    FAN_Key = @WRTOwnerKey,");
         vStringBuilder.AppendLine("       WRT_Availability = @WRTAvailability,");
         vStringBuilder.AppendLine("       FED_Key = @WRTFedKey,");
         vStringBuilder.AppendLine("       CEL_Key = @WRTCelKey,");
         vStringBuilder.AppendLine("       WRT_Date = @WRTDateCreated,");
         vStringBuilder.AppendLine("       WRT_Name = @WRTName,");
         vStringBuilder.AppendLine("       WRT_ResultFunction = @WRTResultFunction,");
         vStringBuilder.AppendLine("       WRT_Description = @WRTDescription");
         vStringBuilder.AppendLine("where  WRT_Key = @WRTKey");
         ObjectToData(vSqlCommand, aWorkout);
         vSqlCommand.Parameters.AddWithValue("@WRTKey", aWorkout.WrtKey);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         vSqlCommand.ExecuteNonQuery();
         vSqlCommand.Connection.Close();
     }
 }
Exemple #11
0
 /// <summary>
 ///   Loads the <see cref="SqlCommand"/> parameters with values from an <see cref="Workout"/>.
 /// </summary>
 /// <param name="aSqlCommand">A <see cref="SqlDataReader"/> argument.</param>
 /// <param name="aWorkout">A <see cref="Workout"/> argument.</param>
 public static void ObjectToData(SqlCommand aSqlCommand, Workout aWorkout)
 {
     aSqlCommand.Parameters.AddWithValue("@WRTName", aWorkout.WrtName);
     aSqlCommand.Parameters.AddWithValue("@WRTAvailability", aWorkout.WrtAvailability);
     aSqlCommand.Parameters.AddWithValue("@WRTDescription", aWorkout.WrtDescription);
     aSqlCommand.Parameters.AddWithValue("@WRTOwnerKey", aWorkout.WrtOwnerKey);
     aSqlCommand.Parameters.AddWithValue("@WRTResultFunction", aWorkout.WrtResultFunction);
     aSqlCommand.Parameters.AddWithValue("@WRTDateCreated", DateTime.Parse(aWorkout.DateCreated));
     if (aWorkout.CelKey < 1)
     {
         aSqlCommand.Parameters.AddWithValue("@WRTCelKey", DBNull.Value);
     }
     else
     {
         aSqlCommand.Parameters.AddWithValue("@WRTCelKey", aWorkout.CelKey);
     }
     if (aWorkout.FedKey < 1)
     {
         aSqlCommand.Parameters.AddWithValue("@WRTFedKey", DBNull.Value);
     }
     else
     {
         aSqlCommand.Parameters.AddWithValue("@WRTFedKey", aWorkout.FedKey);
     }
 }
Exemple #12
0
 /// <summary>
 ///   The overloaded Load method that will return a specific <see cref="Workout"/>, with keys in the <c>aWorkout</c> argument.
 /// </summary>
 /// <param name="aWorkout">A <see cref="Workout"/>.</param>
 /// <exception cref="ArgumentNullException">If <c>aWorkout</c> argument is <c>null</c>.</exception>
 /// <exception cref="Exception">If no record is found.</exception>
 public static void Load(Workout aWorkout)
 {
     if (aWorkout == null)
     {
         throw new ArgumentNullException("aWorkout");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = BuildSQL();
         vStringBuilder.AppendLine("and t1.WRT_Key = @WRTKey");
         vSqlCommand.Parameters.AddWithValue("@WRTKey", aWorkout.WrtKey);
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader())
         {
             if (!vSqlDataReader.HasRows)
             {
                 throw new Exception(String.Format("Expected Workout not found: WRT_Key = {0}", aWorkout.WrtKey));
             }
             vSqlDataReader.Read();
             DataToObject(aWorkout, vSqlDataReader);
             vSqlDataReader.Close();
         }
         vSqlCommand.Connection.Close();
     }
 }
Exemple #13
0
 /// <summary>
 ///   The overloaded Load method that will fill the <c>WorkoutList</c> property a <see cref="WorkoutCollection"/> object as an
 ///   ordered <c>List</c> of <see cref="Workout"/>, filtered by the filter properties of the passed <see cref="WorkoutCollection"/>.
 /// </summary>
 /// <param name="aWorkoutCollection">The <see cref="WorkoutCollection"/> object that must be filled.</param>
 /// <remarks>
 ///   The filter properties of the <see cref="WorkoutCollection"/> must be correctly completed by the calling application.
 /// </remarks>
 /// <exception cref="ArgumentNullException">If <c>aWorkoutCollection</c> argument is <c>null</c>.</exception>
 public static void Load(WorkoutCollection aWorkoutCollection)
 {
     if (aWorkoutCollection == null)
     {
         throw new ArgumentNullException("aWorkoutCollection");
     }
     using (var vSqlCommand = new SqlCommand()
     {
         CommandType = CommandType.Text,
         Connection = new SqlConnection(Connection.Instance.SqlConnectionString)
     })
     {
         var vStringBuilder = BuildSQL();
         if (aWorkoutCollection.IsFiltered)
         {
             if (aWorkoutCollection.WorkoutFilter.WrtFilter.WrtName != null)
             {
                 vStringBuilder.AppendFormat("where t1.WRT_Name is like '%{0}%", aWorkoutCollection.WorkoutFilter.WrtFilter.WrtName);
             }
             if (aWorkoutCollection.WorkoutFilter.WrtFilter.CelKey > 0)
             {
                 vStringBuilder.AppendLine("and t4.CEL_Key = @CELKey");
                 vSqlCommand.Parameters.AddWithValue("@CELKey", aWorkoutCollection.WorkoutFilter.WrtFilter.CelKey);
             }
             if (aWorkoutCollection.WorkoutFilter.WrtFilter.FedKey > 0)
             {
                 vStringBuilder.AppendFormat("and t3.FED_Key = @FEDKey", aWorkoutCollection.WorkoutFilter.WrtFilter.FedKey);
             }
             if (aWorkoutCollection.WorkoutFilter.WrtFilter.WrtOwnerKey > 0)
             {
                 vStringBuilder.AppendFormat("and t2.FAN_Key = @FANKey", aWorkoutCollection.WorkoutFilter.WrtFilter.WrtOwnerKey);
             }
         }
         vStringBuilder.AppendLine("order by t1.WRT_Name");
         vSqlCommand.CommandText = vStringBuilder.ToString();
         vSqlCommand.Connection.Open();
         using (SqlDataReader vSqlDataReader = vSqlCommand.ExecuteReader())
         {
             while (vSqlDataReader.Read())
             {
                 var vWorkout = new Workout();
                 DataToObject(vWorkout, vSqlDataReader);
                 aWorkoutCollection.WorkoutList.Add(vWorkout);
             }
             vSqlDataReader.Close();
         }
         vSqlCommand.Connection.Close();
     }
 }
 /// <summary>
 /// Call the WebService with a request to Add a Workout
 /// </summary>
 /// <param name="aWorkout">The Workout object to Add</param>
 /// <param name="aFantoken">A fantoken.</param>
 public static void AddWorkout(FanToken aFantoken, Workout aWorkout)
 {
     FanCallHandler.ServiceCall<Workout>(aFantoken, "AddWorkout", aWorkout);
 }