private List <Address> GetExistingAddresses(int personId) { List <Address> addressesToReturn = new List <Address>(); Person_Address xref = new Person_Address(_databaseSmoObjectsAndSettings); xref.PersonID = personId; BaseDataAccess <Person_Address> xrefDAO = new BaseDataAccess <Person_Address>(_databaseSmoObjectsAndSettings); //this get permutation will check the modified state of each property in the dto //if modified it is added to the exact criteria list in this case just the personID List <Person_Address> thisPersonsAddresses = xrefDAO.Get(xref, GetPermutations.ByExplicitCriteria); foreach (Person_Address person_address in thisPersonsAddresses) { Bo.Address address = new Bo.Address(_databaseSmoObjectsAndSettings); address.AddressID = person_address.AddressID; address.GetByPrimaryKey(); addressesToReturn.Add(address); } return(addressesToReturn); }
private List <Contact> GetExistingContacts(int personId) { List <Contact> contactsToReturn = new List <Contact>(); Person_Contact xref = new Person_Contact(_databaseSmoObjectsAndSettings); xref.PersonID = personId; BaseDataAccess <Person_Contact> xrefDAO = new BaseDataAccess <Person_Contact>(_databaseSmoObjectsAndSettings); //this get permutation will check the modified state of each property in the dto //if modified it is added to the exact criteria list in this case just the personID List <Person_Contact> thisPersonsContacts = xrefDAO.Get(xref, GetPermutations.ByExplicitCriteria); foreach (Person_Contact person_contact in thisPersonsContacts) { Bo.Contact contact = new Bo.Contact(_databaseSmoObjectsAndSettings); contact.ContactID = person_contact.ContactID; contact.GetByPrimaryKey(); contactsToReturn.Add(contact); } return(contactsToReturn); }
internal Person GetExistingCustomer(int personId, ref List <Address> addresses, ref List <Contact> contacts) { //instantiate DAO BaseDataAccess <Dto.Person> personDAO = new BaseDataAccess <Dto.Person>(_databaseSmoObjectsAndSettings); //instantiate dto Dto.Person personDTO = new Dto.Person(); Bo.Person personToReturn = new Bo.Person(_databaseSmoObjectsAndSettings); //set the property, in this case we are going to use this as the search criteria personDTO.PersonID = personId; //we know that the criteria that we set is the primary key of the database table, so //choose that as the search permutation List <Dto.Person> listOfPersons = personDAO.Get(personDTO, GetPermutations.ByPrimaryKey); if (listOfPersons != null) { //there should only be one if (listOfPersons.Count == 1) { personToReturn.PersonID = personId; personToReturn.GetByPrimaryKey(); addresses = GetExistingAddresses(personId); contacts = GetExistingContacts(personId); return(personToReturn); } else { throw new ApplicationException(MORE_THAN_ONE_PERSON_RECORD_RETURNED_ERROR_MESSAGE); } } else { //if there is no person then there cannot be dependent address or contact records return(personToReturn); } }
/// <summary> /// Retrieves all Folks from the Database /// </summary> /// <returns></returns> public List <Folks> GetAllFolks() { List <Folks> folksToReturn = null; try { //using the Active Record Pattern to model the database objects and backend CRUD ops BaseDataAccess <Folks> bdAccount = new BaseDataAccess <Folks>(SmoSettings[CONNECTION_STRING_NAME_LOCAL]); folksToReturn = bdAccount.Get(new Folks(), CommonLibrary.Enumerations.GetPermutations.AllByColumnMappings); } catch (Exception ex) { //log the exception information in a log file but do not propogate to the client, send friendly message Application Exception to //bubble up the stack _log.Error("Exception Occurred in GetAllFolks method in FolksDataManager", ex); throw new ApplicationException("Exception Occurred Could not Load Famous Folks from the database"); } return(folksToReturn); }
public void BaseDataAccessGet_True() { List <Post> posts = new List <Post>() { new Post() { id = 1, date = DateTime.Now, imgURL = "", numberOfComments = 1, postContent = "test content 1", postPreviewContent = "preview 1", title = "Post 1" }, new Post() { id = 2, date = DateTime.Now, imgURL = "/img1", numberOfComments = 1, postContent = "test content 2", postPreviewContent = "preview here", title = "Post TWO" } }; var sqlConnectionMock = new Mock <IDbConnection>(); var sqlCommandMock = new Mock <IDbCommand>(); var sqlDataReaderMock = new Mock <IDataReader>(); sqlDataReaderMock.Setup(c => c.FieldCount).Returns(2); sqlDataReaderMock.Setup(c => c.GetFieldType(0)).Returns(typeof(int)); sqlDataReaderMock.Setup(c => c.GetFieldType(1)).Returns(typeof(string)); // Columns sqlDataReaderMock.Setup(c => c.GetName(0)).Returns("Id"); sqlDataReaderMock.Setup(c => c.GetName(1)).Returns("Name"); sqlDataReaderMock.Setup(m => m.GetOrdinal("Id")).Returns(0); // Rows // NOTE: Unfortunately this only works for a single row. sqlDataReaderMock.Setup(c => c.GetValues(It.IsAny <object[]>())).Callback <object[]>( (values) => { values[0] = 1; values[1] = "Luggar"; } ).Returns(2); // Read one row sqlDataReaderMock.SetupSequence(c => c.Read()).Returns(true).Returns(false); DataTable table1 = new DataTable(); table1.Columns.Add("Id", typeof(int)); table1.Columns.Add("Name", typeof(string)); table1.Rows.Add("1", "Luggar"); BaseDataAccess _baseDataAccess = new BaseDataAccess(sqlConnectionMock.Object); sqlConnectionMock.Setup(conn => conn.CreateCommand()).Returns(sqlCommandMock.Object); sqlCommandMock.Setup(command => command.ExecuteReader()).Returns(sqlDataReaderMock.Object); sqlConnectionMock.Setup(conn => conn.CreateCommand()).Returns(sqlCommandMock.Object); DataTable returnDt = _baseDataAccess.Get(sqlCommandMock.Object); sqlConnectionMock.Verify((m => m.Open()), Times.Once()); sqlCommandMock.Verify((m => m.ExecuteReader()), Times.Once()); sqlDataReaderMock.Verify((m => m.Close()), Times.Once()); sqlConnectionMock.Verify((m => m.Close()), Times.Once()); Assert.Equal(table1.Columns.Count, returnDt.Columns.Count); Assert.Equal(table1.Rows[0].Field <int>("Id"), returnDt.Rows[0].Field <int>("Id")); Assert.Equal(table1.Rows[0].Field <string>("Name"), returnDt.Rows[0].Field <string>("Name")); }
/// <summary> /// 根据用户Id查找用户 /// </summary> /// <param name="userId"></param> /// <returns></returns> public SysUser GetUserById(int userId) { return(_dataAccess.Get <SysUser>(userId)); }
public SysPost GetPostById(int postId) { return(_dataAccess.Get <SysPost>(postId)); }
public SysPermission GetPermissionById(int menuId) { var menu = _dataAccess.Get<SysPermission>(menuId); return menu; }
public IList GetAll(Type type) { //BaseDataAccess mgr = new BaseDataAccess(); using (mgr) return(mgr.Get(type)); }
/// <summary> /// 得到一个对象实体 /// </summary> public UserActivity GetModel(int activityId) { return(_dataAccess.Get <UserActivity>(activityId)); }
public SysRole GetRoleById(int roleId) { return(_dataAccess.Get <SysRole>(roleId)); }
public SysDepartment GetDeptById(int postId) { return(_dataAccess.Get <SysDepartment>(postId)); }