Пример #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            FinalDemo.PL.ContactsProperties objContacts = new PL.ContactsProperties();

            if (!String.IsNullOrEmpty(Request.QueryString["Id"]))
            {
                objContacts.Id = Convert.ToInt32(Request.QueryString["Id"].ToString());
            }
            else
            {
                objContacts.Id = 0;
            }
            objContacts.FirstName = txtFirstName.Text.Trim();
            objContacts.LastName = txtLastName.Text.Trim();
            objContacts.Phone = txtPhone.Text.Trim();
            objContacts.Mobile = txtMobile.Text.Trim();
            objContacts.City = txtCity.Text.Trim();
            objContacts.Modified = DateTime.Now;

            if (fileupload1.FileName.Length > 0)
            {
                string str_Upload_File_Save_With_New_Name = System.Guid.NewGuid().ToString() + System.IO.Path.GetExtension(fileupload1.FileName);
                objContacts.ProfiePhoto = str_Upload_File_Save_With_New_Name;

                fileupload1.SaveAs(Server.MapPath("~/upload") + "/" + str_Upload_File_Save_With_New_Name);
            }

            FinalDemo.BAL.ContactsService proxy = new BAL.ContactsService();

            bool result = false;

            if (!String.IsNullOrEmpty(Request.QueryString["Id"]))
            {
                result = proxy.Update(objContacts);
                Response.Redirect("ViewAllContacts.aspx");
            }
            else
            {
                result = proxy.Insert(objContacts);
                Response.Redirect("ViewAllContacts.aspx");
            }
        }
Пример #2
0
        /// <summary>
        /// Populate business objects from the data reader
        /// </summary>
        /// <param name="dataReader">data reader</param>
        /// <returns>list of clContacts</returns>
        internal List<ContactsProperties> PopulateObjectsFromReader(IDataReader dataReader)
        {
            List<ContactsProperties> list = new List<ContactsProperties>();

            while (dataReader.Read())
            {
                ContactsProperties businessObject = new ContactsProperties();
                PopulateBusinessObjectFromReader(businessObject, dataReader);
                list.Add(businessObject);
            }
            return list;
        }
Пример #3
0
        /// <summary>
        /// Populate business object from data reader
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <param name="dataReader">data reader</param>
        internal void PopulateBusinessObjectFromReader(ContactsProperties businessObject, IDataReader dataReader)
        {
            businessObject.Id = dataReader.GetInt32(dataReader.GetOrdinal("Id"));

            if (!dataReader.IsDBNull(dataReader.GetOrdinal("FirstName")))
            {
                businessObject.FirstName = dataReader.GetString(dataReader.GetOrdinal("FirstName"));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal("LastName")))
            {
                businessObject.LastName = dataReader.GetString(dataReader.GetOrdinal("LastName"));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal("City")))
            {
                businessObject.City = dataReader.GetString(dataReader.GetOrdinal("City"));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal("Phone")))
            {
                businessObject.Phone = dataReader.GetString(dataReader.GetOrdinal("Phone"));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal("Mobile")))
            {
                businessObject.Mobile = dataReader.GetString(dataReader.GetOrdinal("Mobile"));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal("ProfiePhoto")))
            {
                businessObject.ProfiePhoto = dataReader.GetString(dataReader.GetOrdinal("ProfiePhoto"));
            }

            if (!dataReader.IsDBNull(dataReader.GetOrdinal("Modified")))
            {
                businessObject.Modified = dataReader.GetDateTime(dataReader.GetOrdinal("Modified"));
            }
        }
Пример #4
0
        /// <summary>
        /// update row in the table
        /// </summary>
        /// <param name="businessObject">business object</param>
        /// <returns>true for successfully updated</returns>
        public bool Update(ContactsProperties businessObject)
        {
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "dbo.[spContacts_Update]";
            sqlCommand.CommandType = CommandType.StoredProcedure;

            // Use connection object of base class
            sqlCommand.Connection = MainConnection;

            try
            {

                sqlCommand.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.Id));
                sqlCommand.Parameters.Add(new SqlParameter("@FirstName", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.FirstName));
                sqlCommand.Parameters.Add(new SqlParameter("@LastName", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.LastName));
                sqlCommand.Parameters.Add(new SqlParameter("@City", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.City));
                sqlCommand.Parameters.Add(new SqlParameter("@Phone", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.Phone));
                sqlCommand.Parameters.Add(new SqlParameter("@Mobile", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.Mobile));
                sqlCommand.Parameters.Add(new SqlParameter("@ProfiePhoto", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.ProfiePhoto));
                sqlCommand.Parameters.Add(new SqlParameter("@Modified", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.Modified));

                MainConnection.Open();

                sqlCommand.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                throw new Exception("clContacts::Update::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
Пример #5
0
        /// <summary>
        /// Select by primary key
        /// </summary>
        /// <param name="keys">primary keys</param>
        /// <returns>clContacts business object</returns>
        public ContactsProperties SelectByPrimaryKey(int keys)
        {
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "dbo.[spContacts_SelectByPrimaryKey]";
            sqlCommand.CommandType = CommandType.StoredProcedure;

            // Use connection object of base class
            sqlCommand.Connection = MainConnection;

            try
            {

                sqlCommand.Parameters.Add(new SqlParameter("@Id", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, keys));

                MainConnection.Open();

                IDataReader dataReader = sqlCommand.ExecuteReader();

                if (dataReader.Read())
                {
                    ContactsProperties businessObject = new ContactsProperties();

                    PopulateBusinessObjectFromReader(businessObject, dataReader);

                    return businessObject;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("clContacts::SelectByPrimaryKey::Error occured.", ex);
            }
            finally
            {
                MainConnection.Close();
                sqlCommand.Dispose();
            }
        }
Пример #6
0
 public bool Update(ContactsProperties businessObject)
 {
     clContactsSql objContactSql = new clContactsSql();
     return objContactSql.Update(businessObject);
 }
Пример #7
0
 public bool Insert(ContactsProperties businessObject)
 {
     clContactsSql objContactSql = new clContactsSql();
     return objContactSql.Insert(businessObject);
 }