public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (ImageGalleryMngEntities context = CreateContext()) { ImageGallery dbItem = context.ImageGallery.FirstOrDefault(o => o.ImageGalleryID == id); if (dbItem == null) { notification.Message = "Item not found!"; return(false); } else { if (!string.IsNullOrEmpty(dbItem.FileUD)) { // remove image fwFactory.RemoveImageFile(dbItem.FileUD); } //dbItem.ImageGalleryClient foreach (ImageGalleryVersion version in dbItem.ImageGalleryVersion.ToArray()) { if (!string.IsNullOrEmpty(version.FileUD)) { // remove image fwFactory.RemoveImageFile(version.FileUD); } context.ImageGalleryVersion.Remove(version); } foreach (ImageGalleryClient client in dbItem.ImageGalleryClient.ToArray()) { context.ImageGalleryClient.Remove(client); } context.ImageGallery.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public bool DeleteInternalRemarkData(int userId, int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (Sample3MngEntities context = CreateContext()) { SampleRemark dbItem = context.SampleRemark.FirstOrDefault(o => o.SampleRemarkID == id); if (dbItem == null) { throw new Exception("Internal Remark not found!"); } else { // check permission if (userId != dbItem.UpdatedBy) { throw new Exception("Can not delete remark from other user!"); } if ((DateTime.Now - dbItem.UpdatedDate.Value).TotalDays > 1) { throw new Exception("Too late to delete this remark, remark can only be deleted within 2 days from the last update!"); } foreach (SampleRemarkImage dbImage in dbItem.SampleRemarkImage.ToArray()) { if (!string.IsNullOrEmpty(dbImage.FileUD)) { fwFactory.RemoveImageFile(dbImage.FileUD); } context.SampleRemarkImage.Remove(dbImage); } context.SampleRemark.Remove(dbItem); context.SaveChanges(); } return(true); } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }
private void cmdRemove_tabTILSOFTFile_Click(object sender, EventArgs e) { foreach (string filePointerUD in txtFileList_tabTILSOFTFile.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None)) { fwFactory.RemoveImageFile(filePointerUD); } MessageBox.Show("done"); }
public void DTO2DB_SampleQARemark(DTO.SampleQARemarkDTO dtoItem, ref SampleQARemark dbItem, string TmpFile, int userId) { // remark AutoMapper.Mapper.Map <DTO.SampleQARemarkDTO, SampleQARemark>(dtoItem, dbItem); // remark image foreach (SampleQARemarkImage dbImage in dbItem.SampleQARemarkImage.ToArray()) { if (!dtoItem.SampleQARemarkImageDTOs.Select(o => o.SampleQARemarkImageID).Contains(dbImage.SampleQARemarkImageID)) { if (!string.IsNullOrEmpty(dbImage.FileUD)) { // remove image file fwFactory.RemoveImageFile(dbImage.FileUD); } dbItem.SampleQARemarkImage.Remove(dbImage); } } foreach (DTO.SampleQARemarkImageDTO dtoImage in dtoItem.SampleQARemarkImageDTOs) { SampleQARemarkImage dbImage; if (dtoImage.SampleQARemarkImageID <= 0) { dbImage = new SampleQARemarkImage(); dbItem.SampleQARemarkImage.Add(dbImage); } else { dbImage = dbItem.SampleQARemarkImage.FirstOrDefault(o => o.SampleQARemarkImageID == dtoImage.SampleQARemarkImageID); } if (dbImage != null) { // change or add images if (dtoImage.HasChanged) { dbImage.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoImage.NewFile, dtoImage.FileUD, dtoImage.FriendlyName); } AutoMapper.Mapper.Map <DTO.SampleQARemarkImageDTO, SampleQARemarkImage>(dtoImage, dbImage); } } }
public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (PLCMngEntities context = CreateContext()) { PLC dbItem = context.PLC.FirstOrDefault(o => o.PLCID == id); if (dbItem == null) { notification.Message = "PLC not found!"; return(false); } else { Module.Framework.DAL.DataFactory frameworkFactory = new Module.Framework.DAL.DataFactory(); foreach (PLCImage dbImage in dbItem.PLCImage) { if (!string.IsNullOrEmpty(dbImage.ImageFile)) { // remove image frameworkFactory.RemoveImageFile(dbImage.ImageFile); } } context.PLC.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message }; return(false); } }
public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (ProductMngEntities context = CreateContext()) { Product dbItem = context.Product.FirstOrDefault(o => o.ProductID == id); if (dbItem == null) { notification.Message = "Product not found!"; return(false); } else { if (!string.IsNullOrEmpty(dbItem.ImageFile)) { // remove image fwFactory.RemoveImageFile(dbItem.ImageFile); } context.Product.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message }; return(false); } }
public void DTO2DB(PurchasingCalendarAppointmentDTO dtoItem, ref PurchasingCalendarAppointment dbItem, string TmpFile, int userId) { if (!string.IsNullOrEmpty(dtoItem.StartDate) && !string.IsNullOrEmpty(dtoItem.StartTime)) { if (DateTime.TryParse(dtoItem.StartDate + " " + dtoItem.StartTime, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { dbItem.StartTime = tmpDate; } } if (!string.IsNullOrEmpty(dtoItem.EndDate) && !string.IsNullOrEmpty(dtoItem.EndTime)) { if (DateTime.TryParse(dtoItem.EndDate + " " + dtoItem.EndTime, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { dbItem.EndTime = tmpDate; } } if (!string.IsNullOrEmpty(dtoItem.RemindDate) && !string.IsNullOrEmpty(dtoItem.RemindTime)) { if (DateTime.TryParse(dtoItem.RemindDate + " " + dtoItem.RemindTime, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { dbItem.RemindTime = tmpDate; } } // attached files foreach (PurchasingCalendarAppointmentAttachedFile dbFile in dbItem.PurchasingCalendarAppointmentAttachedFile.ToArray()) { if (!dtoItem.PurchasingCalendarAppointmentAttachedFileDTOs.Select(o => o.PurchasingCalendarAppointmentAttachedFileID).Contains(dbFile.PurchasingCalendarAppointmentAttachedFileID)) { if (!string.IsNullOrEmpty(dbFile.FileUD)) { // remove image file fwFactory.RemoveImageFile(dbFile.FileUD); } dbItem.PurchasingCalendarAppointmentAttachedFile.Remove(dbFile); } } foreach (PurchasingCalendarAppointmentAttachedFileDTO dtoFile in dtoItem.PurchasingCalendarAppointmentAttachedFileDTOs) { PurchasingCalendarAppointmentAttachedFile dbFile; if (dtoFile.PurchasingCalendarAppointmentAttachedFileID <= 0) { dbFile = new PurchasingCalendarAppointmentAttachedFile(); dbItem.PurchasingCalendarAppointmentAttachedFile.Add(dbFile); } else { dbFile = dbItem.PurchasingCalendarAppointmentAttachedFile.FirstOrDefault(o => o.PurchasingCalendarAppointmentAttachedFileID == dtoFile.PurchasingCalendarAppointmentAttachedFileID); } if (dbFile != null) { // change or add images if (dtoFile.HasChanged) { dbFile.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoFile.NewFile, dtoFile.FileUD, dtoFile.FriendlyName); } Mapper.Map <PurchasingCalendarAppointmentAttachedFileDTO, PurchasingCalendarAppointmentAttachedFile>(dtoFile, dbFile); // updated by, updated date. if (dtoFile.HasChanged) { dbFile.UpdatedBy = userId; dbFile.UpdatedDate = DateTime.Now; } } } if (dtoItem.PurchasingCalendarUserDTOs != null) { foreach (var item in dbItem.PurchasingCalendarUser.ToArray()) { if (!dtoItem.PurchasingCalendarUserDTOs.Select(o => o.PurchasingCalendarUserID).Contains(item.PurchasingCalendarUserID)) { dbItem.PurchasingCalendarUser.Remove(item); } } //map child row foreach (var item in dtoItem.PurchasingCalendarUserDTOs) { PurchasingCalendarUser dbAgendaMngUser; if (item.PurchasingCalendarUserID <= 0) { dbAgendaMngUser = new PurchasingCalendarUser(); dbItem.PurchasingCalendarUser.Add(dbAgendaMngUser); } else { dbAgendaMngUser = dbItem.PurchasingCalendarUser.FirstOrDefault(o => o.PurchasingCalendarUserID == item.PurchasingCalendarUserID); } if (dbAgendaMngUser != null) { Mapper.Map <PurchasingCalendarUserDTO, PurchasingCalendarUser>(item, dbAgendaMngUser); } } } Mapper.Map <PurchasingCalendarAppointmentDTO, PurchasingCalendarAppointment>(dtoItem, dbItem); dbItem.UpdatedDate = DateTime.Now; }
public void DTO2BD(DTO.Employee dtoItem, ref Employee dbItem, string TmpFile, int userId) { //AutoMapper.Mapper.Map<DTO.Employee, Employee>(dtoItem, dbItem); if (dtoItem.AnnualLeaveSettings != null) { //check for child rows deleted foreach (AnnualLeaveSetting dbSetting in dbItem.AnnualLeaveSetting.ToArray()) { if (!dtoItem.AnnualLeaveSettings.Select(o => o.AnnualLeaveSettingID).Contains(dbSetting.AnnualLeaveSettingID)) { dbItem.AnnualLeaveSetting.Remove(dbSetting); } } //map child row foreach (DTO.AnnualLeaveSetting dtoSetting in dtoItem.AnnualLeaveSettings) { AnnualLeaveSetting dbSetting; if (dtoSetting.AnnualLeaveSettingID <= 0) { dbSetting = new AnnualLeaveSetting(); dbItem.AnnualLeaveSetting.Add(dbSetting); } else { dbSetting = dbItem.AnnualLeaveSetting.FirstOrDefault(o => o.AnnualLeaveSettingID == dtoSetting.AnnualLeaveSettingID); } if (dbSetting != null) { AutoMapper.Mapper.Map <DTO.AnnualLeaveSetting, AnnualLeaveSetting>(dtoSetting, dbSetting); } } } if (dtoItem.EmployeeFactorys != null) { foreach (var item in dbItem.EmployeeFactory.ToArray()) { if (!dtoItem.EmployeeFactorys.Select(o => o.EmployeeFactoryID).Contains(item.EmployeeFactoryID)) { dbItem.EmployeeFactory.Remove(item); } } //map child row foreach (var item in dtoItem.EmployeeFactorys) { EmployeeFactory dbEmpFactory; if (item.EmployeeFactoryID <= 0) { dbEmpFactory = new EmployeeFactory(); dbItem.EmployeeFactory.Add(dbEmpFactory); } else { dbEmpFactory = dbItem.EmployeeFactory.FirstOrDefault(o => o.EmployeeFactoryID == item.EmployeeFactoryID); } if (dbEmpFactory != null) { AutoMapper.Mapper.Map <DTO.EmployeeFactory, EmployeeFactory>(item, dbEmpFactory); } } } if (dtoItem.EmployeeResponsibleForDTOs != null) { foreach (var item in dbItem.EmployeeResponsibleFor.ToArray()) { if (!dtoItem.EmployeeResponsibleForDTOs.Select(o => o.ResposibleForID).Contains(item.ResposibleForID)) { dbItem.EmployeeResponsibleFor.Remove(item); } } //map child row foreach (var item in dtoItem.EmployeeResponsibleForDTOs) { EmployeeResponsibleFor dbEmployeeResponsibleFor; if (item.ResposibleForID <= 0 || item.ResposibleForID == null) { dbEmployeeResponsibleFor = new EmployeeResponsibleFor(); dbItem.EmployeeResponsibleFor.Add(dbEmployeeResponsibleFor); } else { dbEmployeeResponsibleFor = dbItem.EmployeeResponsibleFor.FirstOrDefault(o => o.ResposibleForID == item.ResposibleForID); } if (dbEmployeeResponsibleFor != null) { Mapper.Map(item, dbEmployeeResponsibleFor); } } } Mapper.Map(dtoItem, dbItem); dbItem.DateStart = dtoItem.DateStart.ConvertStringToDateTime(); dbItem.DateEnd = dtoItem.DateEnd.ConvertStringToDateTime(); dbItem.DateOfBirth = dtoItem.DateOfBirth.ConvertStringToDateTime(); dbItem.ContractPeriod = dtoItem.ContractPeriod.ConvertStringToDateTime(); dbItem.ContractStartDate = dtoItem.ContractStartDate.ConvertStringToDateTime(); // // map the field only for user with special permission // if (dtoItem.NeedToUpdateManagerData && fwFactory.HasSpecialPermission(userId, Module.Framework.ConstantIdentifier.SPECIAL_PERMISSION_EMPLOYEE_MANAGER_NOTE)) { dbItem.ManagerNote = dtoItem.ManagerNote; // manager attached files if (dtoItem.EmployeeFileDTOs != null) { foreach (var item in dbItem.EmployeeFile.ToArray()) { if (!dtoItem.EmployeeFileDTOs.Select(o => o.EmployeeFileID).Contains(item.EmployeeFileID)) { if (!string.IsNullOrEmpty(item.FileUD)) { fwFactory.RemoveImageFile(item.FileUD); } dbItem.EmployeeFile.Remove(item); } } //map child row foreach (var item in dtoItem.EmployeeFileDTOs) { EmployeeFile dbFile; if (item.EmployeeFileID <= 0) { dbFile = new EmployeeFile(); dbItem.EmployeeFile.Add(dbFile); } else { dbFile = dbItem.EmployeeFile.FirstOrDefault(o => o.EmployeeFileID == item.EmployeeFileID); } if (dbFile != null) { AutoMapper.Mapper.Map <DTO.EmployeeFileDTO, EmployeeFile>(item, dbFile); if (item.HasChanged) { dbFile.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, item.NewFile, dbFile.FileUD, item.FriendlyName); } } } } // contract files if (dtoItem.EmployeeContractDTOs != null) { foreach (var item in dbItem.EmployeeContract.ToArray()) { if (!dtoItem.EmployeeContractDTOs.Select(o => o.EmployeeContractID).Contains(item.EmployeeContractID)) { if (!string.IsNullOrEmpty(item.FileUD)) { fwFactory.RemoveImageFile(item.FileUD); } dbItem.EmployeeContract.Remove(item); } } //map child row foreach (var item in dtoItem.EmployeeContractDTOs) { EmployeeContract dbContract; if (item.EmployeeContractID <= 0) { dbContract = new EmployeeContract(); dbItem.EmployeeContract.Add(dbContract); } else { dbContract = dbItem.EmployeeContract.FirstOrDefault(o => o.EmployeeContractID == item.EmployeeContractID); } if (dbContract != null) { AutoMapper.Mapper.Map <DTO.EmployeeContractDTO, EmployeeContract>(item, dbContract); dbContract.ValidFrom = item.ValidFrom.ConvertStringToDateTime(); if (item.HasChanged) { dbContract.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, item.NewFile, dbContract.FileUD, item.FriendlyName); } } } } } if (dtoItem.factoryAccesses != null) { foreach (var item in dbItem.QAQCFactoryAccess.ToArray()) { if (!dtoItem.factoryAccesses.Select(o => o.QAQCFactoryAccessID).Contains(item.QAQCFactoryAccessID)) { dbItem.QAQCFactoryAccess.Remove(item); } } //map child row foreach (var item in dtoItem.factoryAccesses) { QAQCFactoryAccess dbfac; if (item.QAQCFactoryAccessID <= 0) { dbfac = new QAQCFactoryAccess(); dbItem.QAQCFactoryAccess.Add(dbfac); } else { dbfac = dbItem.QAQCFactoryAccess.FirstOrDefault(o => o.QAQCFactoryAccessID == item.QAQCFactoryAccessID); } if (dbfac != null) { Mapper.Map(item, dbfac); } } } }
public void DTO2DB_ProductBreakDown(DTO.ProductBreakDownData dtoItem, ref ProductBreakDown dbItem, string tempFile, int userId) { // ProductBreakDown AutoMapper.Mapper.Map <DTO.ProductBreakDownData, ProductBreakDown>(dtoItem, dbItem); // ProductBreakDown: Category [Progress on Database] foreach (var dbCategory in dbItem.ProductBreakDownCategory.ToArray()) { if (!dtoItem.ProductBreakDownCategory.Select(o => o.ProductBreakDownCategoryID).Contains(dbCategory.ProductBreakDownCategoryID)) { // Category image foreach (var dbCategoryImage in dbCategory.ProductBreakDownCategoryImage.ToArray()) { if (!string.IsNullOrEmpty(dbCategoryImage.FileUD)) { // Remove Files fwFactory.RemoveImageFile(dbCategoryImage.FileUD); } // Remove ProductBreakDownCategoryImage dbCategory.ProductBreakDownCategoryImage.Remove(dbCategoryImage); } // Category type foreach (var dbCategoryType in dbCategory.ProductBreakDownCategoryType.ToArray()) { // Detail foreach (var dbDetail in dbCategoryType.ProductBreakDownDetail.ToArray()) { dbCategoryType.ProductBreakDownDetail.Remove(dbDetail); } dbCategory.ProductBreakDownCategoryType.Remove(dbCategoryType); } // Remove ProductBreakDownCategory dbItem.ProductBreakDownCategory.Remove(dbCategory); } } // ProductBreakDown: Category [Progress on DTO] foreach (var dtoCategory in dtoItem.ProductBreakDownCategory) { ProductBreakDownCategory dbCategory; if (dtoCategory.ProductBreakDownCategoryID < 0) { dbCategory = new ProductBreakDownCategory(); dbItem.ProductBreakDownCategory.Add(dbCategory); } else { dbCategory = dbItem.ProductBreakDownCategory.FirstOrDefault(o => o.ProductBreakDownCategoryID == dtoCategory.ProductBreakDownCategoryID); } if (dbCategory != null) { AutoMapper.Mapper.Map <DTO.ProductBreakDownCategoryData, ProductBreakDownCategory>(dtoCategory, dbCategory); // Category image foreach (var dbCategoryImage in dbCategory.ProductBreakDownCategoryImage.ToArray()) { if (!dtoCategory.ProductBreakDownCategoryImage.Select(o => o.ProductBreakDownCategoryImageID).Contains(dbCategoryImage.ProductBreakDownCategoryImageID)) { if (!string.IsNullOrEmpty(dbCategoryImage.FileUD)) { fwFactory.RemoveImageFile(dbCategoryImage.FileUD); } dbCategory.ProductBreakDownCategoryImage.Remove(dbCategoryImage); } } // Category type foreach (var dbCategoryType in dbCategory.ProductBreakDownCategoryType.ToArray()) { if (!dtoCategory.ProductBreakDownCategoryType.Select(o => o.ProductBreakDownCategoryTypeID).Contains(dbCategoryType.ProductBreakDownCategoryTypeID)) { // Remove detail foreach (var dbDetail in dbCategoryType.ProductBreakDownDetail.ToArray()) { dbCategoryType.ProductBreakDownDetail.Remove(dbDetail); } dbCategory.ProductBreakDownCategoryType.Remove(dbCategoryType); } } // Category image foreach (var dtoCategoryImage in dtoCategory.ProductBreakDownCategoryImage) { ProductBreakDownCategoryImage dbCategoryImage; if (dtoCategoryImage.ProductBreakDownCategoryImageID < 0) { dbCategoryImage = new ProductBreakDownCategoryImage(); dbCategory.ProductBreakDownCategoryImage.Add(dbCategoryImage); } else { dbCategoryImage = dbCategory.ProductBreakDownCategoryImage.FirstOrDefault(o => o.ProductBreakDownCategoryImageID == dtoCategoryImage.ProductBreakDownCategoryImageID); } if (dbCategoryImage != null) { // Progress category image if (dtoCategoryImage.HasChange.HasValue && dtoCategoryImage.HasChange.Value) { dbCategoryImage.FileUD = fwFactory.CreateFilePointer(tempFile, dtoCategoryImage.NewFile, dtoCategoryImage.FileUD, dtoCategoryImage.FriendlyName); } AutoMapper.Mapper.Map <DTO.ProductBreakDownCategoryImageData, ProductBreakDownCategoryImage>(dtoCategoryImage, dbCategoryImage); } } // Category type foreach (var dtoCategoryType in dtoCategory.ProductBreakDownCategoryType) { ProductBreakDownCategoryType dbCategoryType; if (dtoCategoryType.ProductBreakDownCategoryTypeID < 0) { dbCategoryType = new ProductBreakDownCategoryType(); dbCategory.ProductBreakDownCategoryType.Add(dbCategoryType); } else { dbCategoryType = dbCategory.ProductBreakDownCategoryType.FirstOrDefault(o => o.ProductBreakDownCategoryTypeID == dtoCategoryType.ProductBreakDownCategoryTypeID); } if (dbCategoryType != null) { AutoMapper.Mapper.Map <DTO.ProductBreakDownCategoryTypeData, ProductBreakDownCategoryType>(dtoCategoryType, dbCategoryType); foreach (var dbDetail in dbCategoryType.ProductBreakDownDetail.ToArray()) { if (!dtoCategoryType.ProductBreakDownDetail.Select(s => s.ProductBreakDownDetailID).Contains(dbDetail.ProductBreakDownDetailID)) { dbCategoryType.ProductBreakDownDetail.Remove(dbDetail); } } foreach (var dtoDetail in dtoCategoryType.ProductBreakDownDetail) { ProductBreakDownDetail dbDetail; if (dtoDetail.ProductBreakDownDetailID <= 0) { dbDetail = new ProductBreakDownDetail(); dbCategoryType.ProductBreakDownDetail.Add(dbDetail); } else { dbDetail = dbCategoryType.ProductBreakDownDetail.FirstOrDefault(o => o.ProductBreakDownDetailID == dtoDetail.ProductBreakDownDetailID); } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.ProductBreakDownDetailData, ProductBreakDownDetail>(dtoDetail, dbDetail); } } } } } } }
public void DTO2DB_MaterialTestReport(DTO.MaterialTestReportDTO dtoItem, ref MaterialTestReport dbItem, string TmpFile, int userId) { foreach (MaterialTestReportFile dbFile in dbItem.MaterialTestReportFile.ToArray()) { if (!dtoItem.MaterialTestReportFileDTOs.Select(o => o.MaterialTestReportFileID).Contains(dbFile.MaterialTestReportFileID)) { if (!string.IsNullOrEmpty(dbFile.FileUD)) { // remove file fwFactory.RemoveImageFile(dbFile.FileUD); } dbItem.MaterialTestReportFile.Remove(dbFile); } } foreach (DTO.MaterialTestReportFileDTO dtoFile in dtoItem.MaterialTestReportFileDTOs) { MaterialTestReportFile dbFile; if (dtoFile.MaterialTestReportFileID <= 0) { dbFile = new MaterialTestReportFile(); dbItem.MaterialTestReportFile.Add(dbFile); } else { dbFile = dbItem.MaterialTestReportFile.FirstOrDefault(o => o.MaterialTestReportFileID == dtoFile.MaterialTestReportFileID); } if (dbFile != null) { // change or add file if (dtoFile.ScanHasChange) { dtoFile.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoFile.ScanNewFile, dtoFile.FileUD, dtoFile.FriendlyName); } AutoMapper.Mapper.Map <DTO.MaterialTestReportFileDTO, MaterialTestReportFile>(dtoFile, dbFile); } } if (dtoItem.MaterialTestReportFileDTOs != null) { foreach (MaterialTestReportFile item in dbItem.MaterialTestReportFile.ToList()) { if (!dtoItem.MaterialTestReportFileDTOs.Select(s => s.MaterialTestReportFileID).Contains(item.MaterialTestReportFileID)) { dbItem.MaterialTestReportFile.Remove(item); } } foreach (DTO.MaterialTestReportFileDTO dto in dtoItem.MaterialTestReportFileDTOs) { MaterialTestReportFile item; if (dto.MaterialTestReportFileID < 0) { item = new MaterialTestReportFile(); dbItem.MaterialTestReportFile.Add(item); } else { item = dbItem.MaterialTestReportFile.FirstOrDefault(s => s.MaterialTestReportFileID == dto.MaterialTestReportFileID); } if (item != null) { AutoMapper.Mapper.Map <DTO.MaterialTestReportFileDTO, MaterialTestReportFile>(dto, item); } } } if (dtoItem.MaterialTestStandardDTOs != null) { foreach (var item in dbItem.MaterialTestUsingMaterialStandard.ToArray()) { if (!dtoItem.MaterialTestStandardDTOs.Select(o => o.MaterialTestUsingMaterialStandardID).Contains(item.MaterialTestUsingMaterialStandardID)) { dbItem.MaterialTestUsingMaterialStandard.Remove(item); } } foreach (var item in dtoItem.MaterialTestStandardDTOs) { MaterialTestUsingMaterialStandard dbTestStandard = new MaterialTestUsingMaterialStandard(); if (item.MaterialTestUsingMaterialStandardID < 0) { dbItem.MaterialTestUsingMaterialStandard.Add(dbTestStandard); } else { dbTestStandard = dbItem.MaterialTestUsingMaterialStandard.Where(s => s.MaterialTestUsingMaterialStandardID == item.MaterialTestUsingMaterialStandardID).FirstOrDefault(); } if (dbTestStandard != null) { AutoMapper.Mapper.Map <DTO.MaterialTestStandardDTO, MaterialTestUsingMaterialStandard>(item, dbTestStandard); } } } //if (!string.IsNullOrEmpty(dtoItem.TestDate)) //{ // if (DateTime.TryParse(dtoItem.TestDate, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) // { // } //} //if (!string.IsNullOrEmpty(dtoItem.UpdatedDate)) //{ // if (DateTime.TryParse(dtoItem.UpdatedDate, nl, System.Globalization.DateTimeStyles.None, out tmpUpdateDate)) // { // } //} AutoMapper.Mapper.Map <DTO.MaterialTestReportDTO, MaterialTestReport>(dtoItem, dbItem); dbItem.TestDate = dtoItem.TestDate.ConvertStringToDateTime(); }
public void DTO2DB_CushionTestReport(DTO.CushionTestReportDTO dtoItem, ref CushionTestReport dbItem, string TmpFile, int userId) { foreach (CushionTestReportFile dbFile in dbItem.CushionTestReportFile.ToArray()) { if (!dtoItem.CushionTestReportFileDTOs.Select(o => o.CushionTestReportFileID).Contains(dbFile.CushionTestReportFileID)) { if (!string.IsNullOrEmpty(dbFile.FileUD)) { // remove file fwFactory.RemoveImageFile(dbFile.FileUD); } dbItem.CushionTestReportFile.Remove(dbFile); } } foreach (DTO.CushionTestReportFileDTO dtoFile in dtoItem.CushionTestReportFileDTOs) { CushionTestReportFile dbFile; if (dtoFile.CushionTestReportFileID <= 0) { dbFile = new CushionTestReportFile(); dbItem.CushionTestReportFile.Add(dbFile); } else { dbFile = dbItem.CushionTestReportFile.FirstOrDefault(o => o.CushionTestReportFileID == dtoFile.CushionTestReportFileID); } if (dbFile != null) { // change or add file if (dtoFile.ScanHasChange) { dtoFile.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoFile.ScanNewFile, dtoFile.FileUD, dtoFile.FriendlyName); } AutoMapper.Mapper.Map <DTO.CushionTestReportFileDTO, CushionTestReportFile>(dtoFile, dbFile); } } if (dtoItem.CushionTestReportFileDTOs != null) { foreach (CushionTestReportFile item in dbItem.CushionTestReportFile.ToList()) { if (!dtoItem.CushionTestReportFileDTOs.Select(s => s.CushionTestReportFileID).Contains(item.CushionTestReportFileID)) { dbItem.CushionTestReportFile.Remove(item); } } foreach (DTO.CushionTestReportFileDTO dto in dtoItem.CushionTestReportFileDTOs) { CushionTestReportFile item; if (dto.CushionTestReportFileID < 0) { item = new CushionTestReportFile(); dbItem.CushionTestReportFile.Add(item); } else { item = dbItem.CushionTestReportFile.FirstOrDefault(s => s.CushionTestReportFileID == dto.CushionTestReportFileID); } if (item != null) { AutoMapper.Mapper.Map <DTO.CushionTestReportFileDTO, CushionTestReportFile>(dto, item); } } } if (dtoItem.CushionTestStandardDTOs != null) { foreach (var item in dbItem.CushionTestReportUsingCushionStandard.ToArray()) { if (!dtoItem.CushionTestStandardDTOs.Select(o => o.CushionTestReportUsingCushionStandardID).Contains(item.CushionTestReportUsingCushionStandardID)) { dbItem.CushionTestReportUsingCushionStandard.Remove(item); } } foreach (var item in dtoItem.CushionTestStandardDTOs) { CushionTestReportUsingCushionStandard dbTestStandard = new CushionTestReportUsingCushionStandard(); if (item.CushionTestReportUsingCushionStandardID < 0) { dbItem.CushionTestReportUsingCushionStandard.Add(dbTestStandard); } else { dbTestStandard = dbItem.CushionTestReportUsingCushionStandard.Where(s => s.CushionTestReportUsingCushionStandardID == item.CushionTestReportUsingCushionStandardID).FirstOrDefault(); } if (dbTestStandard != null) { AutoMapper.Mapper.Map <DTO.CushionTestStandardDTO, CushionTestReportUsingCushionStandard>(item, dbTestStandard); } } } AutoMapper.Mapper.Map <DTO.CushionTestReportDTO, CushionTestReport>(dtoItem, dbItem); dbItem.TestDate = dtoItem.TestDate.ConvertStringToDateTime(); }
public void DTO2DB_ProductTesting(DTO.ProductTestingDTO dtoItem, ref ProductTest dbItem, string TmpFile, int userID) { //ADD and Remove file foreach (ProductTestFile dbFile in dbItem.ProductTestFile.ToArray()) { if (!dtoItem.productTestFileDTOs.Select(o => o.ProductTestFileID).Contains(dbFile.ProductTestFileID)) { if (!string.IsNullOrEmpty(dbFile.FileUD)) { // remove file fwFactory.RemoveImageFile(dbFile.FileUD); } dbItem.ProductTestFile.Remove(dbFile); } } foreach (DTO.ProductTestFileDTO dtoFile in dtoItem.productTestFileDTOs) { ProductTestFile dbFile; if (dtoFile.ProductTestFileID <= 0) { dbFile = new ProductTestFile(); dbItem.ProductTestFile.Add(dbFile); } else { dbFile = dbItem.ProductTestFile.FirstOrDefault(o => o.ProductTestFileID == dtoFile.ProductTestFileID); } if (dbFile != null) { // change or add file if (dtoFile.ScanHasChange) { dtoFile.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoFile.ScanNewFile, dtoFile.FileUD, dtoFile.FriendlyName); } AutoMapper.Mapper.Map <DTO.ProductTestFileDTO, ProductTestFile>(dtoFile, dbFile); } } if (dtoItem.productTestFileDTOs != null) { foreach (var item in dbItem.ProductTestFile.ToArray()) { if (!dtoItem.productTestFileDTOs.Select(s => s.ProductTestFileID).Contains(item.ProductTestFileID)) { dbItem.ProductTestFile.Remove(item); } } foreach (var item in dtoItem.productTestFileDTOs) { ProductTestFile dbProductFile = new ProductTestFile(); if (item.ProductTestFileID < 0) { dbItem.ProductTestFile.Add(dbProductFile); } else { dbProductFile = dbItem.ProductTestFile.Where(s => s.ProductTestFileID == item.ProductTestFileID).FirstOrDefault(); } if (dbProductFile != null) { AutoMapper.Mapper.Map <DTO.ProductTestFileDTO, ProductTestFile>(item, dbProductFile); } } } if (dtoItem.productTestStandardDTOs != null) { foreach (var item in dbItem.ProductTestUsingTestStandard.ToArray()) { if (!dtoItem.productTestStandardDTOs.Select(o => o.ProductTestUsingTestStandardID).Contains(item.ProductTestUsingTestStandardID)) { dbItem.ProductTestUsingTestStandard.Remove(item); } } foreach (var item in dtoItem.productTestStandardDTOs) { ProductTestUsingTestStandard dbTestStandard = new ProductTestUsingTestStandard(); if (item.ProductTestUsingTestStandardID < 0) { dbItem.ProductTestUsingTestStandard.Add(dbTestStandard); } else { dbTestStandard = dbItem.ProductTestUsingTestStandard.Where(s => s.ProductTestUsingTestStandardID == item.ProductTestUsingTestStandardID).FirstOrDefault(); } if (dbTestStandard != null) { AutoMapper.Mapper.Map <DTO.ProductTestStandardDTO, ProductTestUsingTestStandard>(item, dbTestStandard); } } } AutoMapper.Mapper.Map <DTO.ProductTestingDTO, ProductTest>(dtoItem, dbItem); if (!string.IsNullOrEmpty(dtoItem.TestDate)) { if (DateTime.TryParse(dtoItem.TestDate, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { dbItem.TestDate = tmpDate; } } if (!string.IsNullOrEmpty(dtoItem.UpdatedDate)) { if (DateTime.TryParse(dtoItem.UpdatedDate, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { dbItem.UpdatedDate = tmpDate; } } //dbItem.UpdatedDate = dtoItem.UpdatedDate.ConvertStringToDateTime(); //dbItem.TestDate = dtoItem.TestDate.ConvertStringToDateTime(); }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification) { DTO.DefectsDTO defetcsDTO = ((JObject)dtoItem).ToObject <DTO.DefectsDTO>(); notification = new Notification { Type = NotificationType.Success }; _TempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; try { using (var context = CreateContext()) { Defects defects = null; if (id == 0) { defects = new Defects(); context.Defects.Add(defects); } if (id > 0) { defects = context.Defects.FirstOrDefault(o => o.DefectID == id); } if (defects == null) { notification = new Notification { Type = NotificationType.Error, Message = "Can't Find Data" }; return(false); } else { //process tdfile foreach (DTO.DefectsImageDTO image in defetcsDTO.defectsImageDTOs.Where(o => o.ScanHasChange)) { image.FileUD = fwFactory.CreateFilePointer(this._TempFolder, image.ScanNewFile, image.FileUD); } this.converter.DTO2DB_Defects(defetcsDTO, ref defects); //remove tdfile foreach (DefectsImage dbDFImage in context.DefectsImage.Local.Where(o => o.Defects == null).ToList()) { if (!string.IsNullOrEmpty(dbDFImage.FileUD)) { fwFactory.RemoveImageFile(dbDFImage.FileUD); } } //remove orphan context.DefectsImage.Local.Where(o => o.Defects == null).ToList().ForEach(o => context.DefectsImage.Remove(o)); context.SaveChanges(); dtoItem = this.GetData(defects.DefectID, out notification); return(true); } } } catch (Exception ex) { notification = new Notification { Type = NotificationType.Error, Message = ex.Message }; return(false); } }