public async Task <DeleteTreatmentResponse> DeleteTreatmentAsync(DeleteTreatmentRequest request) { var response = new DeleteTreatmentResponse(); TreatmentEntity entity = await _treatmentRepository.GetTreatmentById(request.Id); if (entity == null) { response.StatusCode = (int)HttpStatusCode.NotFound; return(response); } bool status = await _treatmentRepository.DeleteTreatmentAsync(entity); if (status) { response.StatusCode = (int)HttpStatusCode.OK; } else { response.StatusCode = (int)HttpStatusCode.BadRequest; //TODO (okandavut) : LOGGING _logger.LogWarning(""); } return(response); }
/// <summary> Retrieves the related entity of type 'TreatmentEntity', using a relation of type 'n:1'</summary> /// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param> /// <returns>A fetched entity of type 'TreatmentEntity' which is related to this entity.</returns> public virtual TreatmentEntity GetSingleTreatment(bool forceFetch) { if ((!_alreadyFetchedTreatment || forceFetch || _alwaysFetchTreatment) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode) { bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.TreatmentEntityUsingTreatmentId); TreatmentEntity newEntity = new TreatmentEntity(); bool fetchResult = false; if (performLazyLoading) { AddToTransactionIfNecessary(newEntity); fetchResult = newEntity.FetchUsingPK(this.TreatmentId); } if (fetchResult) { newEntity = (TreatmentEntity)GetFromActiveContext(newEntity); } else { if (!_treatmentReturnsNewIfNotFound) { RemoveFromTransactionIfNecessary(newEntity); newEntity = null; } } this.Treatment = newEntity; _alreadyFetchedTreatment = fetchResult; } return(_treatment); }
public async Task <UpdateTreatmentResponse> UpdateTreatmentsAsync(UpdateTreatmentRequest request) { var response = new UpdateTreatmentResponse(); TreatmentEntity entity = await _treatmentRepository.GetTreatmentById(request.Id); if (entity == null) { response.StatusCode = (int)HttpStatusCode.NotFound; return(response); } entity.Description = request.Description; entity.Title = request.Title; var result = await _treatmentRepository.UpdateTreatmentsAsync(entity); if (result) { response.StatusCode = (int)HttpStatusCode.OK; } else { response.StatusCode = (int)HttpStatusCode.InternalServerError; _logger.LogError("An Error occurred"); } return(response); }
public void Update(Treatment item) { var treatmentEntity = new TreatmentEntity(); treatmentMapper.MapToEntity(item, treatmentEntity); treatmentRepository.Update(treatmentEntity); }
public ActionResult Image(int index, long treatmentId, bool calibration) { var treatment = new TreatmentEntity(treatmentId); if (treatment.IsNew) { throw new HttpException(404, SharedRes.Error.NotFound_Treatment); } // make sure the user has access to this treatment if (!Permissions.UserHasPermission("View", treatment)) { throw new HttpException(401, SharedRes.Error.Unauthorized_Treatment); } var cache = new LinqMetaData().ImageCache.FirstOrDefault( x => x.LookupKey == treatmentId && (x.Description == (calibration ? ("Calibration-" + index) : ("Finger-" + index)))); if (cache == null) { throw new HttpException(404, ViewRes.Treatment.NoImageAvailable); } return(File(cache.Image, "image/png")); }
public void Remove(Treatment treatment) { var treatmentEntity = new TreatmentEntity(); treatmentMapper.MapToEntity(treatment, treatmentEntity); treatmentRepository.Delete(treatmentEntity); }
public void Add(Treatment treatment) { var treatmentEntity = new TreatmentEntity(); treatmentMapper.MapToEntity(treatment, treatmentEntity); treatmentRepository.Create(treatmentEntity); }
public void MapToEntity(TreatmentReport treatmentReport, TreatmentReportEntity treatmentReportEntity) { if (treatmentReportEntity != null && treatmentReport != null) { treatmentReportEntity.Id = treatmentReport.Id; treatmentReportEntity.Conclusion = treatmentReport.Conclusion; treatmentReportEntity.Comment = treatmentReport.Comment; if (treatmentReport.CurrentTreatment != null) { var treatmentEntity = new TreatmentEntity(); treatmentMapper.MapToEntity(treatmentReport.CurrentTreatment, treatmentEntity); treatmentReportEntity.TreatmentId = treatmentEntity.Id; } if (treatmentReport.Medicines != null && treatmentReport.Medicines.Any()) { var medicineRepository = MedicineRepository.GetInstance(); foreach (var medicine in treatmentReport.Medicines) { var medicineEntity = medicineRepository.GetItemById(medicine.Id); treatmentReportEntity.Medicines.Add(medicineEntity); } } } }
/// <summary> setups the sync logic for member _treatment</summary> /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param> private void SetupSyncTreatment(IEntityCore relatedEntity) { if (_treatment != relatedEntity) { DesetupSyncTreatment(true, true); _treatment = (TreatmentEntity)relatedEntity; this.PerformSetupSyncRelatedEntity(_treatment, new PropertyChangedEventHandler(OnTreatmentPropertyChanged), "Treatment", EPICCentralDL.RelationClasses.StaticSeverityRelations.TreatmentEntityUsingTreatmentIdStatic, true, ref _alreadyFetchedTreatment, new string[] { }); } }
/// <summary>Private CTor for deserialization</summary> /// <param name="info"></param> /// <param name="context"></param> protected PatientPrescanQuestionEntity(SerializationInfo info, StreamingContext context) : base(info, context) { _treatment = (TreatmentEntity)info.GetValue("_treatment", typeof(TreatmentEntity)); if (_treatment != null) { _treatment.AfterSave += new EventHandler(OnEntityAfterSave); } _treatmentReturnsNewIfNotFound = info.GetBoolean("_treatmentReturnsNewIfNotFound"); _alwaysFetchTreatment = info.GetBoolean("_alwaysFetchTreatment"); _alreadyFetchedTreatment = info.GetBoolean("_alreadyFetchedTreatment"); this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance()); // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor // __LLBLGENPRO_USER_CODE_REGION_END }
public async Task <AddTreatmentResponse> AddTreatmentAsync(AddTreatmentRequest request) { var response = new AddTreatmentResponse(); TreatmentEntity entity = _treatmentMapper.ToEntity(request); bool status = await _treatmentRepository.AddTreatmentAsync(entity); if (status) { response.StatusCode = (int)HttpStatusCode.Created; } else { response.StatusCode = (int)HttpStatusCode.BadRequest; //TODO (okandavut) : LOGGING _logger.LogWarning(""); } return(response); }
public Task <int> SubmitForm <TDto>(TreatmentEntity entity, TDto dto) where TDto : class { var claimsIdentity = _httpContext.HttpContext.User.Identity as ClaimsIdentity; claimsIdentity.CheckArgumentIsNull(nameof(claimsIdentity)); var claim = claimsIdentity?.FindFirst(t => t.Type.Equals(ClaimTypes.NameIdentifier)); if (!string.IsNullOrEmpty(entity.F_Id)) { entity.Modify(entity.F_Id); entity.F_LastModifyUserId = claim?.Value; return(_service.UpdateAsync(entity, dto)); } else { entity.Create(); entity.F_CreatorUserId = claim?.Value; return(_service.InsertAsync(entity)); } }
public ActionResult Sectors(string fingerDesc, long treatmentId, bool colored = false, bool filtered = false) { var treatment = new TreatmentEntity(treatmentId); if (treatment.IsNew) { throw new HttpException(404, SharedRes.Error.NotFound_Treatment); } // make sure the user has access to this treatment if (!Permissions.UserHasPermission("View", treatment)) { throw new HttpException(401, SharedRes.Error.Unauthorized_Treatment); } // set up variables that define the image var index = int.Parse(fingerDesc.Substring(0, 1)) - 1 + (fingerDesc.Substring(1, 1) == "R" ? 0 : 5) + (filtered ? 10 : 0); var flattenedResult = Flattened(index, treatmentId, colored); if (flattenedResult is FileContentResult) { // get requested sector using (var sectorImage = Utilities.Treatment.ImageManipulation.CreateSectorBiofields( Bitmap.FromStream(new MemoryStream(((FileContentResult)flattenedResult).FileContents)), treatment.AnalysisResults.First( x => x.FingerDesc == fingerDesc))) { using (var stream = new MemoryStream()) { sectorImage.Save(stream, ImageFormat.Png); return(File(stream.ToArray(), "image/png")); } } } return(flattenedResult); }
public ActionResult SystemComparison(long treatmentId) { var treatment = new TreatmentEntity(treatmentId); if (treatment.IsNew) { throw new HttpException(404, SharedRes.Error.NotFound_Treatment); } // make sure the user has access to this treatment if (!Permissions.UserHasPermission("View", treatment)) { throw new HttpException(401, SharedRes.Error.Unauthorized_Treatment); } using (var stream = new MemoryStream()) { using (var image = Utilities.Treatment.SystemComparison.PlotNSData(treatment.AnalysisResults, treatment.Patient.Gender)) { image.Save(stream, ImageFormat.Png); return(File(stream.ToArray(), "image/png")); } } }
public async Task <bool> DeleteTreatmentAsync(TreatmentEntity entity) { _dbContext.Treatments.Remove(entity); return(await SaveAsync()); }
public async Task <bool> AddTreatmentAsync(TreatmentEntity entity) { await _dbContext.Treatments.AddAsync(entity); return(await SaveAsync()); }
/// <summary> Removes the sync logic for member _treatment</summary> /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param> /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param> private void DesetupSyncTreatment(bool signalRelatedEntity, bool resetFKFields) { this.PerformDesetupSyncRelatedEntity(_treatment, new PropertyChangedEventHandler(OnTreatmentPropertyChanged), "Treatment", EPICCentralDL.RelationClasses.StaticSeverityRelations.TreatmentEntityUsingTreatmentIdStatic, true, signalRelatedEntity, "Severities", resetFKFields, new int[] { (int)SeverityFieldIndex.TreatmentId }); _treatment = null; }
public ActionResult Flattened(int index, long treatmentId, bool colored = false) { var treatment = new TreatmentEntity(treatmentId); if (treatment.IsNew) { throw new HttpException(404, SharedRes.Error.NotFound_Treatment); } // make sure the user has access to this treatment if (!Permissions.UserHasPermission("View", treatment)) { throw new HttpException(401, SharedRes.Error.Unauthorized_Treatment); } // set up variables that define the image var finger = (index % 5 + 1) + (index % 10 >= 5 ? "L" : "R"); var filtered = (index >= 10); var fingerEntity = new LinqMetaData().AnalysisResult.First( x => x.TreatmentId == treatmentId && x.FingerDesc.Contains(finger) && x.IsFiltered == filtered); var cache = new LinqMetaData().ImageCache.FirstOrDefault( x => x.LookupKey == treatmentId && (x.Description == (colored ? ("Colorized-" + index) : ("Flattened-" + index)))); // create colorized if (cache == null) { cache = new LinqMetaData().ImageCache.FirstOrDefault( x => x.LookupKey == treatmentId && (x.Description == ("Finger-" + index))); if (cache == null) { throw new HttpException(404, ViewRes.Treatment.NoImageAvailable); } using (var image = new Bitmap(new MemoryStream(cache.Image)) as Image) { Image colorized = null; if (colored) { colorized = Utilities.Treatment.ImageManipulation.CreateColorizedImages( (Bitmap)image, finger + '-' + index, fingerEntity.NoiseLevel); } using (var flattenedColorizedImage = Utilities.Treatment.ImageManipulation.ProcessFullBiofieldInnerEllipse(finger, filtered, colorized ?? image, treatmentId)) { if (colorized != null) { colorized.Dispose(); } using (var mem = new MemoryStream()) { flattenedColorizedImage.Save(mem, ImageFormat.Png); cache = new ImageCacheEntity { LookupKey = treatmentId, Description = colored ? "Colorized-" + index : "Flattened-" + index, Image = mem.ToArray() }; cache.Save(); } } } } return(File(cache.Image, "image/png")); }
public async Task <bool> UpdateTreatmentsAsync(TreatmentEntity entity) { _dbContext.Treatments.Update(entity); return(await SaveAsync()); }
public Task <int> UpdateForm(TreatmentEntity entity) { return(_service.UpdateAsync(entity)); }
public long Add(V0100.Objects.Treatment treatment) { DeviceEntity device = GetDevice(); if (device.DeviceState != DeviceState.Active) { throw new WebFaultException <string>(V0100.Constants.StatusSubcode.DEVICE_STATE_INVALID, HttpStatusCode.NotAcceptable); } if (TreatmentUtils.GetByUid(treatment.Guid) != null) { throw new WebFaultException <string>(V0100.Constants.StatusSubcode.TREATMENT_INVALID, HttpStatusCode.Conflict); } PatientEntity patient = PatientUtils.GetByUid(treatment.PatientGuid); if (patient == null) { throw new WebFaultException <string>(V0100.Constants.StatusSubcode.PATIENT_NOT_FOUND, HttpStatusCode.PreconditionFailed); } CalibrationEntity calibration = CalibrationUtils.GetByUid(treatment.CalibrationGuid); if (calibration == null) { throw new WebFaultException <string>(V0100.Constants.StatusSubcode.CALIBRATION_NOT_FOUND, HttpStatusCode.PreconditionFailed); } ImageSetEntity energizedImageSet = ImageSetUtils.GetByUid(treatment.EnergizedImageSetGuid); if (energizedImageSet == null) { throw new WebFaultException <string>(V0100.Constants.StatusSubcode.IMAGE_SET_NOT_FOUND, HttpStatusCode.PreconditionFailed); } ImageSetEntity fingerImageSet = null; if (treatment.FingerImageSetGuid != null) { fingerImageSet = ImageSetUtils.GetByUid(treatment.FingerImageSetGuid); if (fingerImageSet == null) { throw new WebFaultException <string>(V0100.Constants.StatusSubcode.IMAGE_SET_NOT_FOUND, HttpStatusCode.PreconditionFailed); } } // TODO: Refactor this into the utilities class. // Need to consider if it is worth it. The utilities classes exist to make support for // multiple versions easier. Unlike the other data layer objects, this is more complicated // and will need to be refactored differently. TreatmentEntity treatmentEntity = new TreatmentEntity { UniqueIdentifier = treatment.Guid, PatientId = patient.PatientId, CalibrationId = calibration.CalibrationId, TreatmentType = (TreatmentType)Enum.Parse(typeof(TreatmentType), treatment.TreatmentType.ToString()), TreatmentTime = treatment.TreatmentTime, PerformedBy = treatment.PerformedBy, EnergizedImageSetId = energizedImageSet.ImageSetId, FingerImageSetId = fingerImageSet != null ? fingerImageSet.ImageSetId : (long?)null, SoftwareVersion = treatment.SoftwareVersion, FirmwareVersion = treatment.FirmwareVersion, AnalysisTime = treatment.AnalysisTime, PatientPrescanQuestion = new PatientPrescanQuestionEntity { AlcoholQuestion = treatment.AlcoholQuestion, WheatQuestion = treatment.WheatQuestion, CaffeineQuestion = treatment.CaffeineQuestion } }; foreach (V0100.Objects.NBAnalysisResult result in treatment.NBAnalysisResults) { NBAnalysisResultEntity resultEntity = treatmentEntity.NBAnalysisResults.AddNew(); resultEntity.OrganSystemId = (short)ConvertAnalysisGroup(result.NBAnalysisGroup); resultEntity.ResultScoreFiltered = result.ResultScoreFiltered; resultEntity.ResultScoreUnfiltered = result.ResultScoreUnfiltered; resultEntity.ProbabilityFiltered = result.ProbabilityFiltered; resultEntity.ProbabilityUnfiltered = result.ProbabilityUnfiltered; } foreach (V0100.Objects.AnalysisResult result in treatment.AnalysisResults) { AnalysisResultEntity resultEntity = treatmentEntity.AnalysisResults.AddNew(); resultEntity.AnalysisTime = result.AnalysisTime; resultEntity.IsFiltered = result.IsFiltered; resultEntity.FingerDesc = result.FingerDescription; resultEntity.FingerType = result.FingerType; resultEntity.SectorNumber = result.SectorNumber; resultEntity.StartAngle = result.StartAngle; resultEntity.EndAngle = result.EndAngle; resultEntity.SectorArea = result.SectorArea; resultEntity.IntegralArea = result.IntegralArea; resultEntity.NormalizedArea = result.NormalizedArea; resultEntity.AverageIntensity = result.AverageIntensity; resultEntity.Entropy = result.Entropy; resultEntity.FormCoefficient = result.FormCoefficient; resultEntity.FractalCoefficient = result.FractalCoefficient; resultEntity.JsInteger = result.JsInteger; resultEntity.CenterX = result.CenterX; resultEntity.CenterY = result.CenterY; resultEntity.RadiusMin = result.RadiusMin; resultEntity.RadiusMax = result.RadiusMax; resultEntity.AngleOfRotation = result.AngleOfRotation; resultEntity.Form2 = result.Form2; resultEntity.NoiseLevel = result.NoiseLevel; resultEntity.BreakCoefficient = result.BreakCoefficient; resultEntity.SoftwareVersion = result.SoftwareVersion; resultEntity.AI1 = result.AI1; resultEntity.AI2 = result.AI2; resultEntity.AI3 = result.AI3; resultEntity.AI4 = result.AI4; resultEntity.Form11 = result.Form11; resultEntity.Form12 = result.Form12; resultEntity.Form13 = result.Form13; resultEntity.Form14 = result.Form14; resultEntity.RingThickness = result.RingThickness; resultEntity.RingIntensity = result.RingIntensity; resultEntity.Form2Prime = result.Form2Prime; resultEntity.UserName = result.UserName; } foreach (V0100.Objects.Severity severity in treatment.Severities) { SeverityEntity severityEntity = treatmentEntity.Severities.AddNew(); severityEntity.OrganId = severity.OrganId; severityEntity.PhysicalRight = severity.PhysicalRight; severityEntity.PhysicalLeft = severity.PhysicalLeft; severityEntity.MentalRight = severity.MentalRight; severityEntity.MentalLeft = severity.MentalLeft; } foreach (V0100.Objects.CalculationDebug calculationDebug in treatment.CalculationDebugs) { CalculationDebugDataEntity calculationDebugDataEntity = treatmentEntity.CalculationDebugDatas.AddNew(); calculationDebugDataEntity.FingerSector = calculationDebug.FingerSector; calculationDebugDataEntity.IsFiltered = calculationDebug.IsFiltered; calculationDebugDataEntity.OrganComponent = (OrganComponent)Enum.Parse(typeof(OrganComponent), calculationDebug.OrganComponent, true); calculationDebugDataEntity.Area = calculationDebug.Area; calculationDebugDataEntity.AverageIntensity = calculationDebug.AverageIntensity; calculationDebugDataEntity.BreakCoefficient = calculationDebug.BreakCoefficient; calculationDebugDataEntity.Entropy = calculationDebug.Entropy; calculationDebugDataEntity.NS = calculationDebug.NS; calculationDebugDataEntity.Fractal = calculationDebug.Fractal; calculationDebugDataEntity.Form = calculationDebug.Form; calculationDebugDataEntity.Form2 = calculationDebug.Form2; calculationDebugDataEntity.AI1 = calculationDebug.AI1; calculationDebugDataEntity.AI2 = calculationDebug.AI2; calculationDebugDataEntity.AI3 = calculationDebug.AI3; calculationDebugDataEntity.AI4 = calculationDebug.AI4; calculationDebugDataEntity.Form11 = calculationDebug.Form11; calculationDebugDataEntity.Form12 = calculationDebug.Form12; calculationDebugDataEntity.Form13 = calculationDebug.Form13; calculationDebugDataEntity.Form14 = calculationDebug.Form14; calculationDebugDataEntity.RingIntensity = calculationDebug.RingIntensity; calculationDebugDataEntity.RingThickness = calculationDebug.RingThickness; calculationDebugDataEntity.Form2Prime = calculationDebug.Form2Prime; calculationDebugDataEntity.EPICBaseScore = calculationDebug.EPICBaseScore; calculationDebugDataEntity.EPICBonusScore = calculationDebug.EPICBonusScore; calculationDebugDataEntity.EPICScore = calculationDebug.EPICScore; calculationDebugDataEntity.EPICScaledScore = calculationDebug.EPICScaledScore; calculationDebugDataEntity.EPICRank = calculationDebug.EPICRank; calculationDebugDataEntity.LRRank = calculationDebug.LRRank; calculationDebugDataEntity.LRScore = calculationDebug.LRScore; calculationDebugDataEntity.LRScaledScore = calculationDebug.LRScaledScore; calculationDebugDataEntity.SumZScore = calculationDebug.SumZScore; } treatmentEntity.Save(true); return(treatmentEntity.TreatmentId); }
public ActionResult View(long treatmentId, Treatment model, [ModelBinder(typeof(DataTablesRequestModelBinder))] DataTablesRequestModel dtRequestModel) { var treatment = new TreatmentEntity(treatmentId); if (treatment.IsNew) { throw new HttpException(404, SharedRes.Error.NotFound_Treatment); } // make sure the user has access to this treatment if (!Permissions.UserHasPermission("View", treatment)) { throw new HttpException(401, SharedRes.Error.Unauthorized_Treatment); } // make sure user has access to this page if (!RoleUtils.IsUserServiceAdmin() && model.Page != TreatmentPage.Summary && model.Page != TreatmentPage.System && model.Page != TreatmentPage.Definitions) { throw new HttpException(401, SharedRes.Error.Unauthorized); } // make sure treatment can be accessed by this user model.License = LicenseMode.Full; model.Name = treatment.Patient.FirstName + " " + treatment.Patient.MiddleInitial + " " + treatment.Patient.LastName; model.DateOfBirth = treatment.Patient.BirthDate; model.Gender = treatment.Patient.Gender; var age = treatment.TreatmentTime.Year - treatment.Patient.BirthDate.Year; if (treatment.TreatmentTime < treatment.Patient.BirthDate.AddYears(age)) { age--; } model.Age = age; model.VisitDate = treatment.TreatmentTime; // only load data used for each page // severities is used on the summary and the raw report page if (model.Page == TreatmentPage.Summary || model.Page == TreatmentPage.RawReport) { model.Severities = new LinqMetaData().OrganSystemOrgan .Where(x => x.LicenseOrganSystem.LicenseMode == model.License) .OrderBy(x => x.ReportOrder) .OrderBy(x => x.LicenseOrganSystem.ReportOrder) .SelectMany(x => x.Organ.Severities.Where(y => y.TreatmentId == treatmentId)) .DistinctBy(x => x.Organ.Description.Replace(" - Left", "").Replace(" - Right", "")); } // organ systems is only used on the summary page if (model.Page == TreatmentPage.Summary) { model.OrganSystems = new LinqMetaData().LicenseOrganSystem.Where(x => x.LicenseMode == model.License).OrderBy( x => x.ReportOrder).Select(x => x.OrganSystem); model.PatientPrescanQuestion = treatment.PatientPrescanQuestion; } // load all analysis results for the raw data page if (model.Page == TreatmentPage.Raw || model.Page == TreatmentPage.Summary) { model.Raw = new LinqMetaData().AnalysisResult.Where(x => x.TreatmentId == model.TreatmentId); } // load the debug data for the raw report page if (model.Page == TreatmentPage.RawReport) { model.Debug = GetDebugData(new LinqMetaData().CalculationDebugData.Where(x => x.TreatmentId == model.TreatmentId), model.Severities, model.License); model.NBScores = new LinqMetaData().NBAnalysisResult.Where(x => x.TreatmentId == model.TreatmentId); } // only load images for the images page if (!Request.IsAjaxRequest() && !ControllerContext.IsChildAction) { // get database images var energizedImages = Utilities.Treatment.ImageRetrievalHelper.GetPatientImages(treatment.EnergizedImageSetId); var calibrationImages = Utilities.Treatment.ImageRetrievalHelper.GetCalibrationImageSet(treatment.CalibrationId); // save in cache for a few minutes var caches = new LinqMetaData().ImageCache.Where( x => x.LookupKey == treatmentId && (x.Description.StartsWith("Finger-") || x.Description.StartsWith("Calibration-"))).Select(x => x.Description).ToList(); // save extracted images to database for (var i = 0; i < energizedImages.Count; i++) { if (caches.All(x => x != "Finger-" + i)) { using (var mem = new MemoryStream()) { energizedImages[i].Image.Save(mem, ImageFormat.Png); new ImageCacheEntity { LookupKey = treatmentId, Description = "Finger-" + i, Image = mem.ToArray() }.Save(); energizedImages[i].Image.Dispose(); } } } for (var i = 0; i < calibrationImages.Count; i++) { if (caches.All(x => x != "Calibration-" + i)) { using (var mem = new MemoryStream()) { calibrationImages[i].Image.Save(mem, ImageFormat.Png); new ImageCacheEntity { LookupKey = treatmentId, Description = "Calibration-" + i, Image = mem.ToArray() }.Save(); calibrationImages[i].Image.Dispose(); } } } } ViewResult result = View(model); if (dtRequestModel == null) { return(result); } return(Query(result, dtRequestModel)); }