/// <summary> /// Create a SecurityCheck /// </summary> /// <param name="currentUser"></param> /// <param name="user"></param> /// <param name="appID"></param> /// <param name="overrideID"></param> /// <param name="dc"></param> /// <param name="dataRepository"></param> /// <param name="uow"></param> public SecurityCheckVMDC CreateSecurityCheck(string currentUser, string user, string appID, string overrideID, SecurityCheckDC dc, IRepository <SecurityCheck> dataRepository, IUnitOfWork uow) { try { #region Parameter validation // Validate parameters if (string.IsNullOrEmpty(currentUser)) { throw new ArgumentOutOfRangeException("currentUser"); } if (string.IsNullOrEmpty(user)) { throw new ArgumentOutOfRangeException("user"); } if (string.IsNullOrEmpty(appID)) { throw new ArgumentOutOfRangeException("appID"); } if (null == dc) { throw new ArgumentOutOfRangeException("dc"); } if (null == dataRepository) { throw new ArgumentOutOfRangeException("dataRepository"); } if (null == uow) { throw new ArgumentOutOfRangeException("uow"); } #endregion using (uow) { // Create a new ID for the SecurityCheck item dc.Code = Guid.NewGuid(); // Map data contract to model SecurityCheck destination = Mapper.Map <SecurityCheckDC, SecurityCheck>(dc); // Add the new item dataRepository.Add(destination); // Commit unit of work uow.Commit(); } // Create aggregate data contract SecurityCheckVMDC returnObject = new SecurityCheckVMDC(); // Add new item to aggregate returnObject.SecurityCheckItem = dc; return(returnObject); } catch (Exception e) { //Prevent exception from propogating across the service interface ExceptionManager.ShieldException(e); return(null); } }
/// <summary> /// Retrieve a SecurityCheck with associated lookups /// </summary> /// <param name="currentUser"></param> /// <param name="user"></param> /// <param name="appID"></param> /// <param name="overrideID"></param> /// <param name="code"></param> /// <param name="dataRepository"></param> /// <param name="uow"></param> /// <returns></returns> public SecurityCheckVMDC GetSecurityCheck(string currentUser, string user, string appID, string overrideID, string code, IUnitOfWork uow, IRepository <SecurityCheck> dataRepository , IRepository <Staff> checkerRepository , IRepository <Customer> customerRepository , IRepository <Country> liaisonCountryRepository , IRepository <ReasonForDelay> reasonForDelayRepository , IRepository <BCSNumber> bSCNumberRepository , IRepository <Server> serverRepository , IRepository <Staff> staffRepository , IRepository <Organisation> teamRepository , IRepository <Organisation> commandRepository , IRepository <Organisation> locationRepository ) { try { #region Parameter validation // Validate parameters if (string.IsNullOrEmpty(currentUser)) { throw new ArgumentOutOfRangeException("currentUser"); } if (string.IsNullOrEmpty(user)) { throw new ArgumentOutOfRangeException("user"); } if (string.IsNullOrEmpty(appID)) { throw new ArgumentOutOfRangeException("appID"); } if (null == dataRepository) { throw new ArgumentOutOfRangeException("dataRepository"); } if (null == uow) { throw new ArgumentOutOfRangeException("uow"); } #endregion using (uow) { SecurityCheckDC destination = null; // If code is null then just return supporting lists if (!string.IsNullOrEmpty(code)) { // Convert code to Guid Guid codeGuid = Guid.Parse(code); // Retrieve specific SecurityCheck SecurityCheck dataEntity = dataRepository.Single(x => x.Code == codeGuid); // Convert to data contract for passing through service interface destination = Mapper.Map <SecurityCheck, SecurityCheckDC>(dataEntity); } IEnumerable <Staff> checkerList = checkerRepository.GetAll(x => new { x.StaffNumber }); IEnumerable <Customer> customerList = customerRepository.GetAll(x => new { x.DateRaised }); IEnumerable <Country> liaisonCountryList = liaisonCountryRepository.GetAll(x => new { x.Description }); IEnumerable <ReasonForDelay> reasonForDelayList = reasonForDelayRepository.GetAll(x => new { x.Description }); IEnumerable <BCSNumber> bSCNumberList = bSCNumberRepository.GetAll(x => new { x.Description }); IEnumerable <Server> serverList = serverRepository.GetAll(x => new { x.Number }); IEnumerable <Staff> staffList = staffRepository.GetAll(x => new { x.StaffNumber }); IEnumerable <Organisation> teamList = teamRepository.GetAll(x => new { x.Name }); IEnumerable <Organisation> commandList = commandRepository.GetAll(x => new { x.Name }); IEnumerable <Organisation> locationList = locationRepository.GetAll(x => new { x.Name }); List <StaffDC> checkerDestinationList = Mapper.Map <List <StaffDC> >(checkerList); List <CustomerDC> customerDestinationList = Mapper.Map <List <CustomerDC> >(customerList); List <CountryDC> liaisonCountryDestinationList = Mapper.Map <List <CountryDC> >(liaisonCountryList); List <ReasonForDelayDC> reasonForDelayDestinationList = Mapper.Map <List <ReasonForDelayDC> >(reasonForDelayList); List <BCSNumberDC> bSCNumberDestinationList = Mapper.Map <List <BCSNumberDC> >(bSCNumberList); List <ServerDC> serverDestinationList = Mapper.Map <List <ServerDC> >(serverList); List <StaffDC> staffDestinationList = Mapper.Map <List <StaffDC> >(staffList); List <OrganisationDC> teamDestinationList = Mapper.Map <List <OrganisationDC> >(teamList); List <OrganisationDC> commandDestinationList = Mapper.Map <List <OrganisationDC> >(commandList); List <OrganisationDC> locationDestinationList = Mapper.Map <List <OrganisationDC> >(locationList); // Create aggregate contract SecurityCheckVMDC returnObject = new SecurityCheckVMDC(); returnObject.SecurityCheckItem = destination; returnObject.CheckerList = checkerDestinationList; returnObject.CustomerList = customerDestinationList; returnObject.LiaisonCountryList = liaisonCountryDestinationList; returnObject.ReasonForDelayList = reasonForDelayDestinationList; returnObject.BSCNumberList = bSCNumberDestinationList; returnObject.ServerList = serverDestinationList; returnObject.StaffList = staffDestinationList; returnObject.TeamList = teamDestinationList; returnObject.CommandList = commandDestinationList; returnObject.LocationList = locationDestinationList; return(returnObject); } } catch (Exception e) { //Prevent exception from propogating across the service interface ExceptionManager.ShieldException(e); return(null); } }