Exemplo n.º 1
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region /*--------- Create ---------*\
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Converts the  object properties to SQL paramters and executes the create  procedure 
        /// and updates the object with the SQL data by reference.
        /// </summary>
        /// <param name="JournalsObj">Model object.</param>
        /// <returns>The result of create query.</returns>
        //--------------------------------------------------------------------
        public bool Create(JournalsModel JournalsObj)
        {
            bool result = false;
            using (SqlConnection myConnection = GetSqlConnection())
            {
                SqlCommand myCommand = new SqlCommand("[dbo].[Journals_Create]", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                //----------------------------------------------------------------------------------------------
                // Set the parameters
                //----------------------------------------------------------------------------------------------
				myCommand.Parameters.Add("@JournalCode", SqlDbType.VarChar).Value = JournalsObj.JournalCode;
				myCommand.Parameters.Add("@FullTitle", SqlDbType.VarChar).Value = JournalsObj.FullTitle;
				myCommand.Parameters.Add("@ShortTitle", SqlDbType.VarChar).Value = JournalsObj.ShortTitle;
				myCommand.Parameters.Add("@JournalSubCode", SqlDbType.VarChar).Value = JournalsObj.JournalSubCode;
				myCommand.Parameters.Add("@JournalOwner", SqlDbType.Int).Value = JournalsObj.JournalOwner;
				myCommand.Parameters.Add("@Note", SqlDbType.VarChar).Value = JournalsObj.Note;

                //----------------------------------------------------------------------------------------------
                // Execute the command
                //----------------------------------------------------------------------------------------------
                myConnection.Open();
                if (myCommand.ExecuteNonQuery() > 0)
                {
                    result = true;
                    //Get ID value from database and set it in object

                }
                myConnection.Close();
                return result;
                //----------------------------------------------------------------------------------------------
            }
        }
Exemplo n.º 2
0
 public ActionResult Update(JournalsModel JournalsObj)
 {
     //------------------------------------------
     //Check ModelState
     //------------------------------------------
     if (!ModelState.IsValid)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Invalid data"));
     }
     //------------------------------------------
     try
     {
         bool result = JournalsFactor.Update(JournalsObj);
         if (result == true)
         {
             return(List(1, 25, null, null, null, null));
         }
         else
         {
             return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Saving operation faild"));
         }
     }
     catch (Exception ex)
     { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message)); }
 }
Exemplo n.º 3
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region --------------GetObject--------------
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the spesific record.
        /// </summary>
        /// <param name="ID">The model id.</param>
        /// <returns>Model object.</returns>
        //--------------------------------------------------------------------
        public static JournalsModel GetObject(string JournalCode)
        {
            JournalsModel        JournalsObj = null;
            List <JournalsModel> list        = JournalsSqlDataPrvider.Instance.Get(JournalCode);

            if (list != null && list.Count > 0)
            {
                JournalsObj = list[0];
            }
            return(JournalsObj);
        }
Exemplo n.º 4
0
 public ActionResult GetObject(string id)
 {
     try
     {
         JournalsModel JournalsObj = JournalsFactor.GetObject(id);
         if (JournalsObj == null)
         {
             JournalsObj = new JournalsModel();
         }
         return(Json(JournalsObj, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Exemplo n.º 5
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region /*--------- PopulateModelFromIDataReader ---------*\
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Populates model from IDataReader .
        /// </summary>
        /// <param name="reader"></param>
        /// <returns>Model object.</returns>
        //--------------------------------------------------------------------
        private JournalsModel PopulateModelFromIDataReader(IDataReader reader)
        {
            //Create a new object
            JournalsModel JournalsObj = new JournalsModel();
            //Fill the object with data

			//------------------------------------------------
			//[JournalCode]
			//------------------------------------------------
			if (reader["JournalCode"] != DBNull.Value)
			    JournalsObj.JournalCode = (string)reader["JournalCode"];
			//------------------------------------------------
			//------------------------------------------------
			//[FullTitle]
			//------------------------------------------------
			if (reader["FullTitle"] != DBNull.Value)
			    JournalsObj.FullTitle = (string)reader["FullTitle"];
			//------------------------------------------------
			//------------------------------------------------
			//[ShortTitle]
			//------------------------------------------------
			if (reader["ShortTitle"] != DBNull.Value)
			    JournalsObj.ShortTitle = (string)reader["ShortTitle"];
			//------------------------------------------------
			//------------------------------------------------
			//[JournalSubCode]
			//------------------------------------------------
			if (reader["JournalSubCode"] != DBNull.Value)
			    JournalsObj.JournalSubCode = (string)reader["JournalSubCode"];
			//------------------------------------------------
			//------------------------------------------------
			//[JournalOwner]
			//------------------------------------------------
			if (reader["JournalOwner"] != DBNull.Value)
			    JournalsObj.JournalOwner = (int)reader["JournalOwner"];
			//------------------------------------------------
			//------------------------------------------------
			//[Note]
			//------------------------------------------------
			if (reader["Note"] != DBNull.Value)
			    JournalsObj.Note = (string)reader["Note"];
			//------------------------------------------------
            //Return the populated object
            return JournalsObj;
        }
Exemplo n.º 6
0
        //------------------------------------------------------------------------------------------------------
        #endregion

        #region --------------Update--------------
        //------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Updates model object by calling sql data provider update method.
        /// </summary>
        /// <param name="JournalsObj">The model object.</param>
        /// <returns>The result of update operation.</returns>
        //--------------------------------------------------------------------
        public static bool Update(JournalsModel JournalsObj)
        {
            return(JournalsSqlDataPrvider.Instance.Update(JournalsObj));
        }