private void AddToIncidentUpdateEvent(IRepository <IncidentUpdateEvent> incidentUpdateEventRepository, IRepository <Staff> staffRepository, Guid incidentCode, string currentUser) { // Add to Incident history IncidentUpdateEvent Guid userWhoUpdatedIncident = Guid.Parse(currentUser); string staffName = staffRepository.Find(new Specification <Staff>(x => x.Code == userWhoUpdatedIncident)).Select(x => x.FirstName + " " + x.LastName).First(); IncidentUpdateEvent incidentUpdateEventItem = new IncidentUpdateEvent(); incidentUpdateEventItem.Code = Guid.NewGuid(); incidentUpdateEventItem.DateTime = DateTime.Now; incidentUpdateEventItem.IncidentCode = incidentCode; incidentUpdateEventItem.Type = "Update"; incidentUpdateEventItem.UpdateBy = staffName; //IncidentUpdateEvent List <IncidentUpdateEvent> incidentUpdateEventList = incidentUpdateEventRepository.Find(new Specification <IncidentUpdateEvent>(x => x.IncidentCode == incidentCode && x.Type == "Update")).ToList(); incidentUpdateEventList = incidentUpdateEventList.OrderBy(x => x.DateTime).ToList(); //Only store last 5 update events (list is ordered by date time (asc) so the elementAt 0 will be the oldest if (incidentUpdateEventList.Count == 5) { incidentUpdateEventRepository.Delete(incidentUpdateEventList.ElementAt(0)); } incidentUpdateEventRepository.Add(incidentUpdateEventItem); }
/// <summary> /// UploadAttachment /// </summary> /// <param name="request">UploadAttachmentRequest information</param> public UploadAttachmentResponse UploadAttachment(IRepository <Attachment> attachmentRepository, IRepository <AttachmentData> attachmentDataRepository, IRepository <IncidentUpdateEvent> incidentUpdateEventRepository, IRepository <Staff> staffRepository, IUnitOfWork uow, IExceptionManager exceptionManager, UploadAttachmentRequest request) { UploadAttachmentResponse ReturnValue = new UploadAttachmentResponse(); try { #region Parameter validation if (null == request) { throw new ArgumentOutOfRangeException("request"); } if (null == attachmentRepository) { throw new ArgumentOutOfRangeException("dataRepository"); } if (null == uow) { throw new ArgumentOutOfRangeException("uow"); } #endregion using (uow) { // Create response message contract bool HasError = false; // Create empty message list List <string> Messages = new List <string>(); var AttachmentData = AutoMapper.Mapper.Map <AttachmentDC, Attachment>(request.Attachment); HasError = AttachmentComponent.UploadAttachment(AttachmentData, request.DocumentBody, attachmentRepository, attachmentDataRepository); //out Messages); //pass back the details of the newly inserted document ReturnValue.Attachment = AutoMapper.Mapper.Map <Attachment, AttachmentDC>(AttachmentData); if (!HasError) { Messages.Add("Added"); // Add to Incident history IncidentUpdateEvent Guid userWhoUpdatedIncident = Guid.Parse(request.UserID); string staffName = staffRepository.Find(new Specification <Staff>(x => x.Code == userWhoUpdatedIncident)).Select(x => x.FirstName + " " + x.LastName).First(); IncidentUpdateEvent incidentUpdateEventItem = new IncidentUpdateEvent(); incidentUpdateEventItem.Code = Guid.NewGuid(); incidentUpdateEventItem.DateTime = DateTime.Now; incidentUpdateEventItem.IncidentCode = AttachmentData.IncidentCode; incidentUpdateEventItem.Type = "Update"; incidentUpdateEventItem.UpdateBy = staffName; //IncidentUpdateEvent List <IncidentUpdateEvent> incidentUpdateEventList = incidentUpdateEventRepository.Find(new Specification <IncidentUpdateEvent>(x => x.IncidentCode == AttachmentData.IncidentCode && x.Type == "Update")).ToList(); incidentUpdateEventList = incidentUpdateEventList.OrderBy(x => x.DateTime).ToList(); //Only store last 5 update events (list is ordered by date time (asc) so the elementAt 0 will be the oldest if (incidentUpdateEventList.Count == 5) { incidentUpdateEventRepository.Delete(incidentUpdateEventList.ElementAt(0)); } incidentUpdateEventRepository.Add(incidentUpdateEventItem); } else { Messages.Add("Failed"); } //if (IsDuplicate) //{ // Messages.Add(MessageComponent.CreateWarningMessage(ResourceInformation.RES_INFORM_DOCUMENT_DUPLICATE)); //} // Convert messages be's to data contracts ReturnValue.Messages = Messages; // Return success/failure indicator ReturnValue.Result = HasError; uow.Commit(); } return(ReturnValue); } catch (Exception e) { //Prevent exception from propogating across the service interface exceptionManager.ShieldException(e); return(null); } }
/// <summary> /// Update a Attachment /// </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 DeleteAttachmentAndData(string currentUser, string user, string appID, string overrideID, string code, byte[] lockID, IRepository <Attachment> attachmentRepository, IRepository <AttachmentData> attachmentdataRepository, IRepository <IncidentUpdateEvent> incidentUpdateEventRepository, IRepository <Staff> staffRepository, 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 (string.IsNullOrEmpty(code)) { throw new ArgumentOutOfRangeException("code"); } //if (lockID.Length==0) throw new ArgumentOutOfRangeException("lockID"); if (null == attachmentRepository) { throw new ArgumentOutOfRangeException("dataRepository"); } if (null == uow) { throw new ArgumentOutOfRangeException("uow"); } #endregion using (uow) { // Convert string to guid Guid codeGuid = Guid.Parse(code); // Find item based on ID Attachment dataEntity = attachmentRepository.Single(x => x.Code == codeGuid, "AttachmentData"); List <AttachmentData> dataToDelete = new List <AttachmentData>(dataEntity.AttachmentData); //Set the row identifier to be the one that i'm trying to delete. Therefore E.F. will error if this has changed since //dataEntity.RowIdentifier = lockID; foreach (AttachmentData currentData in dataToDelete) { attachmentdataRepository.Delete(currentData); } // Delete the item attachmentRepository.Delete(dataEntity); // Add to Incident history IncidentUpdateEvent Guid userWhoUpdatedIncident = Guid.Parse(currentUser); string staffName = staffRepository.Find(new Specification <Staff>(x => x.Code == userWhoUpdatedIncident)).Select(x => x.FirstName + " " + x.LastName).First(); IncidentUpdateEvent incidentUpdateEventItem = new IncidentUpdateEvent(); incidentUpdateEventItem.Code = Guid.NewGuid(); incidentUpdateEventItem.DateTime = DateTime.Now; incidentUpdateEventItem.IncidentCode = dataEntity.IncidentCode; incidentUpdateEventItem.Type = "Update"; incidentUpdateEventItem.UpdateBy = staffName; //IncidentUpdateEvent List <IncidentUpdateEvent> incidentUpdateEventList = incidentUpdateEventRepository.Find(new Specification <IncidentUpdateEvent>(x => x.IncidentCode == dataEntity.IncidentCode && x.Type == "Update")).ToList(); incidentUpdateEventList = incidentUpdateEventList.OrderBy(x => x.DateTime).ToList(); //Only store last 5 update events (list is ordered by date time (asc) so the elementAt 0 will be the oldest if (incidentUpdateEventList.Count == 5) { incidentUpdateEventRepository.Delete(incidentUpdateEventList.ElementAt(0)); } incidentUpdateEventRepository.Add(incidentUpdateEventItem); // Commit unit of work uow.Commit(); } } catch (Exception e) { //Prevent exception from propogating across the service interface exceptionManager.ShieldException(e); } }
/// <summary> /// Create a IncidentUpdateEvent /// </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 IncidentUpdateEventVMDC CreateIncidentUpdateEvent(string currentUser, string user, string appID, string overrideID, IncidentUpdateEventDC dc, IRepository <IncidentUpdateEvent> 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 IncidentUpdateEvent item dc.Code = Guid.NewGuid(); // Map data contract to model IncidentUpdateEvent destination = mappingService.Map <IncidentUpdateEventDC, IncidentUpdateEvent>(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 <IncidentUpdateEvent, IncidentUpdateEventDC>(destination); } // Create aggregate data contract IncidentUpdateEventVMDC returnObject = new IncidentUpdateEventVMDC(); // Add new item to aggregate returnObject.IncidentUpdateEventItem = dc; return(returnObject); } catch (Exception e) { //Prevent exception from propogating across the service interface exceptionManager.ShieldException(e); return(null); } }
/// <summary> /// Retrieve a IncidentUpdateEvent 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 IncidentUpdateEventVMDC GetIncidentUpdateEvent(string currentUser, string user, string appID, string overrideID, string code, IUnitOfWork uow, IRepository <IncidentUpdateEvent> dataRepository , IRepository <Incident> incidentRepository , 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) { IncidentUpdateEventDC 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 IncidentUpdateEvent IncidentUpdateEvent dataEntity = dataRepository.Single(x => x.Code == codeGuid); // Convert to data contract for passing through service interface destination = mappingService.Map <IncidentUpdateEvent, IncidentUpdateEventDC>(dataEntity); } IEnumerable <Incident> incidentList = incidentRepository.GetAll(x => new { x.IncidentID }); List <IncidentDC> incidentDestinationList = mappingService.Map <List <IncidentDC> >(incidentList); // Create aggregate contract IncidentUpdateEventVMDC returnObject = new IncidentUpdateEventVMDC(); returnObject.IncidentUpdateEventItem = destination; returnObject.IncidentList = incidentDestinationList; return(returnObject); } } catch (Exception e) { //Prevent exception from propogating across the service interface exceptionManager.ShieldException(e); return(null); } }
/// <summary> /// Update a IncidentUpdateEvent /// </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 DeleteIncidentUpdateEvent(string currentUser, string user, string appID, string overrideID, string code, string lockID, IRepository <IncidentUpdateEvent> 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 IncidentUpdateEvent 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); } }