public void Delete(Member deleteThis)
        {
            _dataEngine.InitialiseParameterList();
            _dataEngine.AddParameter("@Id", deleteThis.Id.ToString());

            _sqlToExecute = "DELETE FROM [dbo].[Member] WHERE Id = " + _dataEngine.GetParametersForQuery();

            if (!_dataEngine.ExecuteSql(_sqlToExecute))
                throw new Exception("Member - Delete failed");
        }
 public int Insert(Member saveThis)
 {
     try
        {
        _db.Members.InsertOnSubmit(saveThis);
        _db.SubmitChanges();
        return saveThis.Id;
        }
        catch (Exception e)
        {
        throw new Exception(e.Message);
        }
 }
 public void Delete(Member deleteThis)
 {
     try
     {
         if (deleteThis.Id > 0)
         {
             _db.Members.DeleteOnSubmit(deleteThis);
             _db.SubmitChanges(ConflictMode.FailOnFirstConflict);
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
        public int Insert(Member saveThis)
        {
            _dataEngine.InitialiseParameterList();
            _dataEngine.AddParameter("@FirstName", saveThis.FirstName);
            _dataEngine.AddParameter("@LastName", saveThis.LastName);
            _dataEngine.AddParameter("@EmailAddress", saveThis.EmailAddress);
            _dataEngine.AddParameter("@MobileNumber", saveThis.MobileNumber);
            _dataEngine.AddParameter("@MembershipNumber", saveThis.MembershipNumber);

            _sqlToExecute = "INSERT INTO [dbo].[Member] ";
            _sqlToExecute += "([FirstName]";
            _sqlToExecute += ",[LastName]";
            _sqlToExecute += ",[EmailAddress]";
            _sqlToExecute += ",[MobileNumber]";
            _sqlToExecute += ",[MembershipNumber]) ";
            _sqlToExecute += "OUTPUT INSERTED.Id ";
            _sqlToExecute += "VALUES ";
            _sqlToExecute += "(";
            _sqlToExecute += _dataEngine.GetParametersForQuery();
            _sqlToExecute += ")";

            int insertedRowId = 0;

            if (!_dataEngine.ExecuteSql(_sqlToExecute, out insertedRowId))
                throw new Exception("Member - Save failed");

            return insertedRowId;
        }
        /// <summary>
        /// Creates the object from the data returned from the database
        /// </summary>
        /// <returns></returns>
        private Member CreateMemberFromData()
        {
            var member = new Member
            {
                FirstName = _dataEngine.Dr["FirstName"].ToString(),
                LastName = _dataEngine.Dr["LastName"].ToString(),
                EmailAddress = _dataEngine.Dr["EmailAddress"].ToString(),
                MobileNumber = _dataEngine.Dr["MobileNumber"].ToString(),
                MembershipNumber = _dataEngine.Dr["MembershipNumber"].ToString(),
                Id = int.Parse(_dataEngine.Dr["Id"].ToString())
            };

            return member;
        }
        public void Update(Member saveThis)
        {
            _dataEngine.InitialiseParameterList();
            _dataEngine.AddParameter("@FirstName", saveThis.FirstName);
            _dataEngine.AddParameter("@LastName", saveThis.LastName);
            _dataEngine.AddParameter("@EmailAddress", saveThis.EmailAddress);
            _dataEngine.AddParameter("@MobileNumber", saveThis.MobileNumber);
            _dataEngine.AddParameter("@MembershipNumber", saveThis.MembershipNumber);

            _sqlToExecute = "UPDATE [dbo].[Member] SET ";
            _sqlToExecute += "[FirstName] = @FirstName";
            _sqlToExecute += ",[LastName] = @LastName";
            _sqlToExecute += ",[EmailAddress] = @EmailAddress";
            _sqlToExecute += ",[MobileNumber] = @MobileNumber";
            _sqlToExecute += ",[MembershipNumber] = @MembershipNumber ";
            _sqlToExecute += "WHERE [Id] = " + saveThis.Id;

            if (!_dataEngine.ExecuteSql(_sqlToExecute))
                throw new Exception("Member - Update failed");
        }
 public void Update(Member updateThis)
 {
     try
     {
         _db.Members.Attach(updateThis);
         _db.Refresh(RefreshMode.KeepCurrentValues, updateThis);
         _db.SubmitChanges();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }