Ejemplo n.º 1
0
        public void Insert(mmDTObase myDTO)
        {
            using (var mySQL = new SQL.StoredProcedures.SP_INSERT_RENTER(sp_InsertRenter))
            {
                var myResult = mySQL.ExecuteSP(myDTO);
                var data = (SQL.Results.spR_Insert_Renter_Result)myResult;
                if (data.ErrorMessage.Length > 0)
                {
                    throw new Exception(data.ErrorMessage);
                }

            }
        }
Ejemplo n.º 2
0
        public void Update(mmDTObase item)
        {
            var myItem = item;

              //  throw new NotImplementedException();
        }
Ejemplo n.º 3
0
        internal static IList<PropertyInfo> GetDTOproperties(mmDTObase myDTO)
        {
            var sourceType = myDTO.GetType();
                var sourceProperties = sourceType.GetProperties();

                var properties = (from s in sourceProperties
                                  select s).ToList();
                return properties;
        }
Ejemplo n.º 4
0
        internal static IList<SqlParameter> CreateCriteriaParameters(mmDTObase myDTO)
        {
            var _parameters = new List<SqlParameter>();
            var myStuff = DataMapper.GetDTOproperties(myDTO);

            ResourceManager rm = new ResourceManager("MM.DAL.SQL.Properties.Resources", Assembly.GetExecutingAssembly());
            foreach (PropertyInfo pi in myStuff)
            {
                var suffix = pi.Name.ToLower();
                var dbType = GetParmType(pi.PropertyType.Name);
                var myValue = pi.GetValue(myDTO, null);
                var parameterName = rm.GetString("p_" + suffix);
                var myParm = new SqlParameter(parameterName, dbType);
                myParm.Value = myValue;
                _parameters.Add(myParm);
            }
            return _parameters;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Executes the SP.
        /// </summary>
        /// <returns>spResult object</returns>
        public spResult ExecuteSP(mmDTObase myDTO)
        {
            var myData = new DalManager();
             var myResult = new spR_Insert_Renter_Result();
             if (myData.GetConnection(out _mySQLConn)) return null;
             try
             {
                 using (var myAccessCommand = new SqlCommand(_storedProcedureName, _mySQLConn))
                 {
                     myAccessCommand.CommandType = System.Data.CommandType.StoredProcedure;

                     //Get the Address parms for sure
                     var concDTO = (RenterAccountDTO)myDTO;
                     var address = concDTO.Renter.Addresses[0];
                     var myAddresStuff = DataMapper.CreateCriteriaParameters(address);
                     foreach (SqlParameter parm in myAddresStuff)
                     {
                         if (parm.ParameterName.Length > 0)
                         {
                             myAccessCommand.Parameters.Add(parm);
                             System.Diagnostics.Debug.WriteLine("Parameter: " + parm.ParameterName + " - Value: " + parm.Value);
                         }
                     }
                     var phone = concDTO.Renter.ContactInfoItems[0];
                     myAccessCommand.Parameters.AddWithValue("@Phone", phone.ContactInfoItem);
                     myAccessCommand.Parameters.AddWithValue("@ContactType", phone.ContactInfoTypeID);

                     var myStuff = DataMapper.CreateCriteriaParameters(concDTO.Renter);
                     foreach (SqlParameter parm in myStuff)
                     {
                         if (parm.ParameterName.Length > 0)
                         {
                            myAccessCommand.Parameters.Add(parm);
                            System.Diagnostics.Debug.WriteLine("Parameter: " + parm.ParameterName + " - Value: " + parm.Value);
                         }
                     }

                     var query = from SqlParameter myparm in myAccessCommand.Parameters
                                 where myparm.ParameterName == "@RenterID"
                                 select myparm;
                     var outParm = query.FirstOrDefault();
                     outParm.DbType = System.Data.DbType.Int32;
                     outParm.Direction = System.Data.ParameterDirection.Output;
                     outParm.ParameterName = "@AccountID";

                     myAccessCommand.Parameters.AddWithValue("@UserID", concDTO.Renter.CreateUserID);

                     var myCount = myAccessCommand.Parameters.Count;

                     _mySQLConn.Open();
                      myResult.RowsReturned =  myAccessCommand.ExecuteNonQuery();
                     concDTO.Renter.RenterID = (int)myAccessCommand.Parameters["@AccountID"].Value;
                    }
                return myResult;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Error: Failed to act on the data in the DataBase.\n{0}", ex.Message);
                myResult.ErrorMessage = CreateUIMessage(ex.Message);
                return myResult;
            }
            finally
            {
                _mySQLConn.Close();
            }
        }