/// <summary> /// Create a SiteStaff /// </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 SiteStaffVMDC CreateSiteStaff(string currentUser, string user, string appID, string overrideID, SiteStaffDC dc, IRepository <SiteStaff> dataRepository, IUnitOfWork uow, IExceptionManager exceptionManager, IMappingService mappingService) { 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"); } if (null == exceptionManager) { throw new ArgumentOutOfRangeException("exceptionManager"); } if (null == mappingService) { throw new ArgumentOutOfRangeException("mappingService"); } #endregion using (uow) { // Create a new ID for the SiteStaff item dc.Code = Guid.NewGuid(); // Map data contract to model SiteStaff destination = mappingService.Map <SiteStaffDC, SiteStaff>(dc); // Add the new item dataRepository.Add(destination); // Commit unit of work uow.Commit(); // Map model back to data contract to return new row id. dc = mappingService.Map <SiteStaff, SiteStaffDC>(destination); } // Create aggregate data contract SiteStaffVMDC returnObject = new SiteStaffVMDC(); // Add new item to aggregate returnObject.SiteStaffItem = dc; return(returnObject); } catch (Exception e) { //Prevent exception from propogating across the service interface exceptionManager.ShieldException(e); return(null); } }
/// <summary> /// Update a SiteStaff /// </summary> /// <param name="currentUser"></param> /// <param name="user"></param> /// <param name="appID"></param> /// <param name="overrideID"></param> /// <param name="code"></param> /// <param name="lockID"></param> /// <param name="dataRepository"></param> /// <param name="uow"></param> public void DeleteSiteStaff(string currentUser, string user, string appID, string overrideID, string code, string lockID, IRepository <SiteStaff> dataRepository, IUnitOfWork uow, IExceptionManager exceptionManager, IMappingService mappingService) { 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 (string.IsNullOrEmpty(code)) { throw new ArgumentOutOfRangeException("code"); } if (string.IsNullOrEmpty(lockID)) { throw new ArgumentOutOfRangeException("lockID"); } if (null == dataRepository) { throw new ArgumentOutOfRangeException("dataRepository"); } if (null == uow) { throw new ArgumentOutOfRangeException("uow"); } if (null == exceptionManager) { throw new ArgumentOutOfRangeException("exceptionManager"); } if (null == mappingService) { throw new ArgumentOutOfRangeException("mappingService"); } #endregion using (uow) { // Convert string to guid Guid codeGuid = Guid.Parse(code); // Find item based on ID SiteStaff dataEntity = dataRepository.Single(x => x.Code == codeGuid); // Delete the item dataRepository.Delete(dataEntity); // Commit unit of work uow.Commit(); } } catch (Exception e) { //Prevent exception from propogating across the service interface exceptionManager.ShieldException(e); } }
/// <summary> /// Retrieve a SiteStaff 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 SiteStaffVMDC GetSiteStaff(string currentUser, string user, string appID, string overrideID, string code, IUnitOfWork uow, IRepository <SiteStaff> dataRepository , IRepository <Site> siteRepository , IRepository <Staff> staffRepository , IExceptionManager exceptionManager, IMappingService mappingService) { 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"); } if (null == exceptionManager) { throw new ArgumentOutOfRangeException("exceptionManager"); } if (null == mappingService) { throw new ArgumentOutOfRangeException("mappingService"); } #endregion using (uow) { SiteStaffDC 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 SiteStaff SiteStaff dataEntity = dataRepository.Single(x => x.Code == codeGuid); // Convert to data contract for passing through service interface destination = mappingService.Map <SiteStaff, SiteStaffDC>(dataEntity); } IEnumerable <Site> siteList = siteRepository.GetAll(x => new { x.SiteName }); IEnumerable <Staff> staffList = staffRepository.GetAll(x => new { x.StaffNumber }); List <SiteDC> siteDestinationList = mappingService.Map <List <SiteDC> >(siteList); List <StaffDC> staffDestinationList = mappingService.Map <List <StaffDC> >(staffList); // Create aggregate contract SiteStaffVMDC returnObject = new SiteStaffVMDC(); returnObject.SiteStaffItem = destination; returnObject.SiteList = siteDestinationList; returnObject.StaffList = staffDestinationList; return(returnObject); } } catch (Exception e) { //Prevent exception from propogating across the service interface exceptionManager.ShieldException(e); return(null); } }
/// <summary> /// Create a Site /// </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 SiteVMDC CreateSite(string currentUser, string user, string appID, string overrideID, SiteVMDC dc, IRepository <Site> dataRepository, IRepository <SiteStaff> siteStaffRepository, IUnitOfWork uow, IExceptionManager exceptionManager) { 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 == siteStaffRepository) { throw new ArgumentOutOfRangeException("siteStaffRepository"); } if (null == uow) { throw new ArgumentOutOfRangeException("uow"); } #endregion using (uow) { // Create a new ID for the Site item dc.SiteItem.Code = Guid.NewGuid(); // Map data contract to model Site siteDestination = Mapper.Map <SiteDC, Site>(dc.SiteItem); // Add the new item dataRepository.Add(siteDestination); SiteStaff siteStaffItem = null; // Add Deputy Nominated Managers foreach (StaffDC staffItem in dc.DeputyNominatedManagerList) { siteStaffItem = new SiteStaff(); siteStaffItem.Code = Guid.NewGuid(); siteStaffItem.Responsibility = ServiceConstants.SITE_STAFF_RESPONSIBILITY_DEPUTY_NOMINATED_MANAGER; siteStaffItem.SiteCode = siteDestination.Code; siteStaffItem.StaffCode = staffItem.Code; siteStaffRepository.Add(siteStaffItem); } // Add Nominated Manager siteStaffItem = new SiteStaff(); siteStaffItem.Code = Guid.NewGuid(); siteStaffItem.Responsibility = ServiceConstants.SITE_STAFF_RESPONSIBILITY_NOMINATED_MANAGER; siteStaffItem.SiteCode = siteDestination.Code; siteStaffItem.StaffCode = Guid.Parse(dc.NominatedManagerCode); siteStaffRepository.Add(siteStaffItem); // Commit unit of work uow.Commit(); // Map model back to data contract to return new row id. dc.SiteItem = Mapper.Map <Site, SiteDC>(siteDestination); } return(dc); } catch (Exception e) { //Prevent exception from propogating across the service interface exceptionManager.ShieldException(e); return(null); } }