private void AddToIncidentLink(IRepository <IncidentLink> incidentLinkRepository, Guid incidentCode, Customer customer, Incident linkToIncident) { // Create new link String name = ((String.IsNullOrEmpty(customer.FirstName) ? "" : customer.FirstName.Trim()) + " " + (String.IsNullOrEmpty(customer.LastName) ? "" : customer.LastName.Trim())).Trim(); name = name.Substring(0, name.Length >= 50 ? 49 : name.Length).Trim(); IncidentLink linkedCustomer = new IncidentLink() { Code = Guid.NewGuid(), IncidentCode = incidentCode, LinkedIncidentCode = linkToIncident.Code, CustomerName = name, IncidentId = linkToIncident.IncidentID }; // Add linked incident to db incidentLinkRepository.Add(linkedCustomer); }
/// <summary> /// Retrieve a IncidentLink 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 IncidentLinkVMDC GetIncidentLink(string currentUser, string user, string appID, string overrideID, string code, IUnitOfWork uow, IRepository <IncidentLink> dataRepository , IRepository <Incident> incidentRepository , IRepository <Incident> linkedIncidentRepository , 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) { IncidentLinkDC 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 IncidentLink IncidentLink dataEntity = dataRepository.Single(x => x.Code == codeGuid); // Convert to data contract for passing through service interface destination = mappingService.Map <IncidentLink, IncidentLinkDC>(dataEntity); } IEnumerable <Incident> incidentList = incidentRepository.GetAll(x => new { x.IncidentID }); IEnumerable <Incident> linkedIncidentList = linkedIncidentRepository.GetAll(x => new { x.IncidentID }); List <IncidentDC> incidentDestinationList = mappingService.Map <List <IncidentDC> >(incidentList); List <IncidentDC> linkedIncidentDestinationList = mappingService.Map <List <IncidentDC> >(linkedIncidentList); // Create aggregate contract IncidentLinkVMDC returnObject = new IncidentLinkVMDC(); returnObject.IncidentLinkItem = destination; returnObject.IncidentList = incidentDestinationList; returnObject.LinkedIncidentList = linkedIncidentDestinationList; return(returnObject); } } catch (Exception e) { //Prevent exception from propogating across the service interface exceptionManager.ShieldException(e); return(null); } }
/// <summary> /// Create a IncidentLink /// </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 IncidentLinkVMDC CreateIncidentLink(string currentUser, string user, string appID, string overrideID, IncidentLinkDC dc, IRepository <IncidentLink> 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 IncidentLink item dc.Code = Guid.NewGuid(); // Map data contract to model IncidentLink destination = mappingService.Map <IncidentLinkDC, IncidentLink>(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 <IncidentLink, IncidentLinkDC>(destination); } // Create aggregate data contract IncidentLinkVMDC returnObject = new IncidentLinkVMDC(); // Add new item to aggregate returnObject.IncidentLinkItem = dc; return(returnObject); } catch (Exception e) { //Prevent exception from propogating across the service interface exceptionManager.ShieldException(e); return(null); } }
/// <summary> /// Update a IncidentLink /// </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 DeleteIncidentLink(string currentUser, string user, string appID, string overrideID, string code, string lockID, IRepository <IncidentLink> 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 IncidentLink 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); } }