public override bool UpdateData(int userId, int id, ref object dtoItems, out Notification notification) { notification = new Notification(); notification.Type = NotificationType.Success; bool isUpdated = true; ClientSpecificationDTO dtoItem = ((Newtonsoft.Json.Linq.JObject)dtoItems).ToObject <ClientSpecificationDTO>(); try { using (var context = CreateContext()) { ClientSpecification dbItem; dbItem = context.ClientSpecification.FirstOrDefault(o => o.ClientSpecificationID == id); if (dbItem == null) { notification.Type = NotificationType.Error; notification.Message = "Cannot be found data!"; return(false); } if (dtoItem.HasChange) { string pathFile = ("eurofar_standard.docx".Equals(dtoItem.FriendlyName)) ? Setting.AbsoluteUserTempFolder + @"\" : Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; dtoItem.ClientSpecificationFileUD = fwFactory.CreateNoneImageFilePointer(pathFile, dtoItem.NewFile, dtoItem.ClientSpecificationFileUD, dtoItem.FriendlyName); } converter.DTO2DB_ClientSpecification(dtoItem, ref dbItem); dbItem.ClientSpecificationUpdatedBy = userId; dbItem.ClientSpecificationUpdatedDate = DateTime.Now; context.SaveChanges(); dtoItems = GetData(userId, dbItem.ClientSpecificationID, out notification).ResultData; } } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = ex.Message; isUpdated = false; } return(isUpdated); }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.Factory dtoFactory = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.Factory>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (FactoryMng2Entities context = CreateContext()) { Factory dbItem = null; if (id == 0) { dbItem = new Factory(); context.Factory.Add(dbItem); } else { dbItem = context.Factory.FirstOrDefault(o => o.FactoryID == id); } if (dbItem == null) { notification.Message = "Factory not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoFactory.ConcurrencyFlag_String))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } // process image foreach (DTO.FactoryImage dtoImage in dtoFactory.FactoryImages) { if (dtoImage.HasChange) { dtoImage.FileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoImage.NewFile, dtoImage.FileUD); } } // Process business card image foreach (DTO.FactoryBusinessCard dtoCard in dtoFactory.FactoryBusinessCard) { if (dtoCard.FrontHasChange) { dtoCard.FrontFileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCard.FrontNewFile, dtoCard.FrontFileUD); } if (dtoCard.BehindHasChange) { dtoCard.BehindFileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCard.BehindNewFile, dtoCard.BehindFileUD); } } // processing certificate file foreach (DTO.FactoryCertificate dtoCertificate in dtoFactory.FactoryCertificates) { if (dtoCertificate.CertificateFileHasChange) { if (string.IsNullOrEmpty(dtoCertificate.NewCertificateFile)) { fwFactory.RemoveImageFile(dtoCertificate.CertificateFile); } else { dtoCertificate.CertificateFile = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCertificate.NewCertificateFile, dtoCertificate.CertificateFile); } } } // remove Technical Image foreach (FactoryImage dbImage in context.FactoryImage.Local.Where(o => o.Factory == null).ToList()) { if (!string.IsNullOrEmpty(dbImage.FileUD)) { fwFactory.RemoveImageFile(dbImage.FileUD); } } // processing image if (dtoFactory.LogoImage_HasChange) { dtoFactory.LogoImage = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoFactory.LogoImage_NewFile, dtoFactory.LogoImage); } if (dtoFactory.FactoryGalleries != null) { // Pre-event update FactoryGallery foreach (DTO.FactoryGalleryDTO dtoFactoryGallery in dtoFactory.FactoryGalleries.Where(o => o.FactoryGalleryHasChange)) { dtoFactoryGallery.FactoryGalleryUD = fwFactory.CreateNoneImageFilePointer(this._tempFolder, dtoFactoryGallery.FactoryGalleryNewFile, dtoFactoryGallery.FactoryGalleryUD); } } //foreach (DTO.FactoryDocumentDTO dtoDocumentFile in dtoFactory.factoryDocuments) //{ // if (dtoDocumentFile.FactoryDocumentHasChange) // { // if (string.IsNullOrEmpty(dtoDocumentFile.FactoryDocumentNewFile)) // { // fwFactory.RemoveFile(dtoDocumentFile.FactoryDocumentFile); // } // else // { // dtoDocumentFile.FactoryDocumentFile = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoDocumentFile.FactoryDocumentNewFile, dtoDocumentFile.FactoryDocumentFile, dtoDocumentFile.FriendlyName); // } // } //} converter.DTO2BD(dtoFactory, ref dbItem, userId); // //remove orphan item // // FactoryImage context.FactoryImage.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryImage.Remove(o)); // FactoryBusinessCard context.FactoryBusinessCard.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryBusinessCard.Remove(o)); // FactoryDirector context.FactoryDirector.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryDirector.Remove(o)); // FactoryManager context.FactoryManager.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryManager.Remove(o)); // FactoryPricing context.FactoryPricing.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryPricing.Remove(o)); // FactoryResponsiblePerson context.FactoryResponsiblePerson.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryResponsiblePerson.Remove(o)); // SampleTechnical context.FactorySampleTechnical.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactorySampleTechnical.Remove(o)); // FactorySupplier //context.FactoryRawMaterialSupplier.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryRawMaterialSupplier.Remove(o)); context.FactorySupplier.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactorySupplier.Remove(o)); // FactoryInHouseTest context.FactoryInHouseTest.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryInHouseTest.Remove(o)); // FactoryCertificate context.FactoryCertificate.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryCertificate.Remove(o)); //FactoryCapacity By Weeks context.FactoryCapacity.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryCapacity.Remove(o)); //FactoryContactQuickInfo context.FactoryContactQuickInfo.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryContactQuickInfo.Remove(o)); //FactoryProductGroup context.FactoryProductGroup.Local.Where(o => o.Factory == null).ToList().ForEach(o => context.FactoryProductGroup.Remove(o)); dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = userId; // FactoryGallery for Factory(remove value Factory is null) foreach (FactoryGallery dbFactoryGallery in context.FactoryGallery.Where(o => o.Factory == null).ToList()) { fwFactory.RemoveImageFile(dbFactoryGallery.FactoryGalleryUD); context.FactoryGallery.Remove(dbFactoryGallery); } context.SaveChanges(); //Update Permission Factory if (id == 0) { context.Factory2Mng_function_AddFactoryPermissionNew(dbItem.FactoryID); dtoItem = GetData(userId, dbItem.FactoryID, out notification).Data; } return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.FactoryRawMaterial dtoFactoryRawMaterial = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryRawMaterial>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { //Get CompanyID int?companyID = fwFactory.GetCompanyID(userId); using (FactoryRawMaterialMngEntities context = CreateContext()) { FactoryRawMaterial dbItem = null; if (id == 0) { dbItem = new FactoryRawMaterial(); context.FactoryRawMaterial.Add(dbItem); var checkUD = context.FactoryRawMaterial.ToList(); foreach (var item in checkUD) { if (item.FactoryRawMaterialUD == dtoFactoryRawMaterial.FactoryRawMaterialUD) { throw new Exception("Sub Supplier code exists !"); } } } else { dbItem = context.FactoryRawMaterial.FirstOrDefault(o => o.FactoryRawMaterialID == id); } if (dbItem == null) { notification.Message = "Factory Raw Material not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoFactoryRawMaterial.ConcurrencyFlag_String))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } //file processing Library.FileHelper.FileManager fileMng = new Library.FileHelper.FileManager(FrameworkSetting.Setting.AbsoluteFileFolder); string fileNeedDeleted = string.Empty; string thumbnailFileNeedDeleted = string.Empty; foreach (var contractItem in dtoFactoryRawMaterial.SubSupplierContracts.Where(o => o.ContractFileHasChange)) { if (!string.IsNullOrEmpty(contractItem.ContractFile)) { fwFactory.GetDBFileLocation(contractItem.ContractFile, out fileNeedDeleted, out thumbnailFileNeedDeleted); if (!string.IsNullOrEmpty(fileNeedDeleted)) { try { fileMng.DeleteFile(fileNeedDeleted); } catch { } } } if (string.IsNullOrEmpty(contractItem.NewContractFile)) { // remove file registration in File table fwFactory.RemoveFile(contractItem.ContractFile); // reset file in table Contract contractItem.ContractFile = string.Empty; } else { string outDBFileLocation = ""; string outFileFullPath = ""; string outFilePointer = ""; // copy new file fileMng.StoreFile(this._tempFolder + contractItem.NewContractFile, out outDBFileLocation, out outFileFullPath); if (File.Exists(outFileFullPath)) { FileInfo info = new FileInfo(outFileFullPath); // insert/update file registration in database fwFactory.UpdateFile(contractItem.ContractFile, contractItem.NewContractFile, outDBFileLocation, info.Extension, "", (int)info.Length, out outFilePointer); // set file database pointer contractItem.ContractFile = outFilePointer; } } } // processing certificate file foreach (DTO.FactoryRawMaterialCertificate dtoCertificate in dtoFactoryRawMaterial.FactoryRawMaterialCertificates) { if (dtoCertificate.CertificateFileHasChange) { if (string.IsNullOrEmpty(dtoCertificate.NewCertificateFile)) { fwFactory.RemoveImageFile(dtoCertificate.CertificateFile); } else { dtoCertificate.CertificateFile = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCertificate.NewCertificateFile, dtoCertificate.CertificateFile); } } } // Process business card image foreach (DTO.FactoryRawMaterialBusinessCardDTO dtoCard in dtoFactoryRawMaterial.FactoryRawMaterialBusinessCardDTO) { if (dtoCard.FrontHasChange) { dtoCard.FrontFileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCard.FrontNewFile, dtoCard.FrontFileUD); } if (dtoCard.BehindHasChange) { dtoCard.BehindFileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCard.BehindNewFile, dtoCard.BehindFileUD); } } // processing logo image if (dtoFactoryRawMaterial.LogoFile_HasChange) { dtoFactoryRawMaterial.LogoFile = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoFactoryRawMaterial.LogoFile_NewFile, dtoFactoryRawMaterial.LogoFile); } // process image foreach (DTO.FactoryRawMaterialImage dtoImage in dtoFactoryRawMaterial.FactoryRawMaterialImages) { if (dtoImage.HasChange) { dtoImage.FileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoImage.NewFile, dtoImage.FileUD); } } if (dtoFactoryRawMaterial.FactoryRawMaterialGalleryDTO != null) { // Pre-event update FactoryGallery foreach (DTO.FactoryRawMaterialGalleryDTO dtoFactoryGallery in dtoFactoryRawMaterial.FactoryRawMaterialGalleryDTO.Where(o => o.FactoryGalleryHasChange)) { dtoFactoryGallery.FactoryRawMaterialGalleryUD = fwFactory.CreateNoneImageFilePointer(this._tempFolder, dtoFactoryGallery.FactoryGalleryNewFile, dtoFactoryGallery.FactoryRawMaterialGalleryUD); } } // remove Technical Image foreach (FactoryRawMaterialImage dbImage in context.FactoryRawMaterialImage.Local.Where(o => o.FactoryRawMaterial == null).ToList()) { if (!string.IsNullOrEmpty(dbImage.FileUD)) { fwFactory.RemoveImageFile(dbImage.FileUD); } } //attach file foreach (var item in dtoFactoryRawMaterial.materialsPrices.Where(o => o.AttachFileHasChange)) { item.AttachFile = string.Empty; string outDBFileLocation = ""; string outFileFullPath = ""; string outFilePointer = ""; // copy new file fileMng.StoreFile(this._tempFolder + item.NewAttachFile, out outDBFileLocation, out outFileFullPath); if (File.Exists(outFileFullPath)) { FileInfo info = new FileInfo(outFileFullPath); // insert/update file registration in database fwFactory.UpdateFile(item.AttachFile, item.NewAttachFile, outDBFileLocation, info.Extension, "", (int)info.Length, out outFilePointer); // set file database pointer item.AttachFile = outFilePointer; } } foreach (DTO.MaterialsPrice item in dtoFactoryRawMaterial.materialsPrices) { if (item.IsChange == true) { MaterialPriceHistory dbItemPriceHistory = new MaterialPriceHistory(); dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID; dbItemPriceHistory.Price = (decimal)item.OldPrice; dbItemPriceHistory.UpdatedBy = userId; dbItemPriceHistory.UpdatedDate = DateTime.Now; dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID; dbItemPriceHistory.Qty = (decimal)item.OldQty; dbItemPriceHistory.UpdatedBy = userId; dbItemPriceHistory.UpdatedDate = DateTime.Now; dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID; dbItemPriceHistory.StatusID = (int)item.OldStatusID; dbItemPriceHistory.UpdatedBy = userId; dbItemPriceHistory.UpdatedDate = DateTime.Now; dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID; dbItemPriceHistory.ValidFrom = Convert.ToDateTime(item.OldValidFrom); dbItemPriceHistory.UpdatedBy = userId; dbItemPriceHistory.UpdatedDate = DateTime.Now; dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID; dbItemPriceHistory.AttachFileHistory = item.OldAttachFile; dbItemPriceHistory.UpdatedBy = userId; dbItemPriceHistory.UpdatedDate = DateTime.Now; dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID; dbItemPriceHistory.RemarkHistory = item.OldRemark; dbItemPriceHistory.UpdatedBy = userId; dbItemPriceHistory.UpdatedDate = DateTime.Now; context.MaterialPriceHistory.Add(dbItemPriceHistory); } else if (item.AttachFile != item.OldAttachFile) { MaterialPriceHistory dbItemPriceHistory = new MaterialPriceHistory(); dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID; dbItemPriceHistory.Price = (decimal)item.OldPrice; dbItemPriceHistory.UpdatedBy = userId; dbItemPriceHistory.UpdatedDate = DateTime.Now; dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID; dbItemPriceHistory.Qty = (decimal)item.OldQty; dbItemPriceHistory.UpdatedBy = userId; dbItemPriceHistory.UpdatedDate = DateTime.Now; dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID; dbItemPriceHistory.StatusID = (int)item.OldStatusID; dbItemPriceHistory.UpdatedBy = userId; dbItemPriceHistory.UpdatedDate = DateTime.Now; dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID; dbItemPriceHistory.ValidFrom = Convert.ToDateTime(item.OldValidFrom); dbItemPriceHistory.UpdatedBy = userId; dbItemPriceHistory.UpdatedDate = DateTime.Now; dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID; dbItemPriceHistory.AttachFileHistory = item.OldAttachFile; dbItemPriceHistory.UpdatedBy = userId; dbItemPriceHistory.UpdatedDate = DateTime.Now; dbItemPriceHistory.MaterialsPriceID = (int)item.MaterialsPriceID; dbItemPriceHistory.RemarkHistory = item.OldRemark; dbItemPriceHistory.UpdatedBy = userId; dbItemPriceHistory.UpdatedDate = DateTime.Now; context.MaterialPriceHistory.Add(dbItemPriceHistory); } } //convert dto to db converter.DTO2BD(dtoFactoryRawMaterial, ref dbItem); if (!string.IsNullOrEmpty(dbItem.WebAddress)) { dbItem.WebAddress = dbItem.WebAddress.ToLower().Replace("http://", "").Replace("https://", ""); } // FactoryRawMaterialCertificate context.FactoryRawMaterialCertificate.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.FactoryRawMaterialCertificate.Remove(o)); // FactoryInHouseTest context.FactoryRawMaterialTest.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.FactoryRawMaterialTest.Remove(o)); // FactoryRawMaterialPricingPerson context.FactoryRawMaterialPricingPerson.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.FactoryRawMaterialPricingPerson.Remove(o)); // FactoryRawMaterialPricingPerson context.FactoryRawMaterialQualityPerson.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.FactoryRawMaterialQualityPerson.Remove(o)); // FactoryRawMaterialPaymentTerm context.FactoryRawMaterialPaymentTerm.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.FactoryRawMaterialPaymentTerm.Remove(o)); // FactoryRawMaterialMng_SupplierContactQuickInfo_View context.SupplierContactQuickInfo.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.SupplierContactQuickInfo.Remove(o)); context.SupplierDirector.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.SupplierDirector.Remove(o)); context.SupplierManager.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.SupplierManager.Remove(o)); context.SupplierSampleTechnical.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.SupplierSampleTechnical.Remove(o)); context.MaterialsPrice.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.MaterialsPrice.Remove(o)); context.MaterialPriceHistory.Local.Where(o => o.MaterialsPrice == null).ToList().ForEach(o => context.MaterialPriceHistory.Remove(o)); context.FactoryRawMaterialBusinessCard.Local.Where(o => o.FactoryRawMaterial == null).ToList().ForEach(o => context.FactoryRawMaterialBusinessCard.Remove(o)); // FactoryGallery for Factory(remove value Factory is null) foreach (FactoryRawMaterialGallery dbFactoryGallery in context.FactoryRawMaterialGallery.Where(o => o.FactoryRawMaterial == null).ToList()) { fwFactory.RemoveImageFile(dbFactoryGallery.FactoryRawMaterialGalleryUD); context.FactoryRawMaterialGallery.Remove(dbFactoryGallery); } dbItem.CompanyID = companyID; dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = userId; context.SaveChanges(); dtoItem = GetData(userId, dbItem.FactoryRawMaterialID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.PriceListFile dtoPriceListFile = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.PriceListFile>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; List <DTO.PriceListFile> PriceListFileDTOs = new List <DTO.PriceListFile>(); try { using (PriceListFileEntities context = CreateContext()) { PriceListFile dbItem = null; if (id == 0) { dbItem = new PriceListFile(); context.PriceListFile.Add(dbItem); } else { dbItem = context.PriceListFile.FirstOrDefault(o => o.PriceListFileID == id); } if (dbItem == null) { notification.Message = "Data not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoPriceListFile.ConcurrencyFlag_String))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } // processing pdf if (dtoPriceListFile.PDFFileLocation_HasChange) { if (string.IsNullOrEmpty(dtoPriceListFile.NewPDFFile)) { fwFactory.RemoveFile(dtoPriceListFile.PDFFileUD); } else { dtoPriceListFile.PDFFileUD = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoPriceListFile.NewPDFFile, dtoPriceListFile.PDFFileUD, dtoPriceListFile.PDFFriendlyName); } } // processing excel if (dtoPriceListFile.ExcelFileLocation_HasChange) { if (string.IsNullOrEmpty(dtoPriceListFile.NewExcelFile)) { fwFactory.RemoveFile(dtoPriceListFile.ExcelFileUD); } else { dtoPriceListFile.ExcelFileUD = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoPriceListFile.NewExcelFile, dtoPriceListFile.ExcelFileUD, dtoPriceListFile.ExcelFriendlyName); } } converter.DTO2DB(dtoPriceListFile, ref dbItem); dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = userId; context.SaveChanges(); dtoItem = GetData(dbItem.PriceListFileID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public bool UpdateData(int id, ref object dtoItem, int iRequesterID, out Library.DTO.Notification notification) { notification = new Notification(); notification.Type = NotificationType.Success; int number; string indexName; DTO.CushionColor dtoCushionColor = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.CushionColor>(); try { using (var context = CreateContext()) { CushionColor cushionColor = null; if (id == 0) { dtoCushionColor.CreatedBy = iRequesterID; cushionColor = new CushionColor(); context.CushionColor.Add(cushionColor); } else { var item = context.CushionColorMng_CushionColorCheck_View.Where(o => o.CushionColorID == id).FirstOrDefault(); //CheckPermission if (item.isUsed.Value == true) { throw new Exception("You can't update because it used in item other!"); } dtoCushionColor.UpdatedBy = iRequesterID; cushionColor = context.CushionColor.FirstOrDefault(o => o.CushionColorID == id); } if (cushionColor == null) { notification.Message = "Cushion Color not found!"; return(false); } else { // check concurrency if (cushionColor.ConcurrencyFlag != null && !cushionColor.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoCushionColor.ConcurrencyFlag_String))) { notification.Type = NotificationType.Error; notification.Message = Library.Helper.TEXT_CONCURRENCY_CONFLICT; return(false); } converter.DTO2BD(dtoCushionColor, _TempFolder, ref cushionColor); // processing image if (dtoCushionColor.ImageFile_HasChange) { cushionColor.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoCushionColor.ImageFile_NewFile, dtoCushionColor.ImageFile); } // processing test report file 1 if (dtoCushionColor.TestReportFile_HasChange1) { cushionColor.TestReportFile1 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoCushionColor.TestReportFile_NewFile1, dtoCushionColor.TestReportFile1); } // processing test report file 2 if (dtoCushionColor.TestReportFile_HasChange2) { cushionColor.TestReportFile2 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoCushionColor.TestReportFile_NewFile2, dtoCushionColor.TestReportFile2); } // processing test report file 3 if (dtoCushionColor.TestReportFile_HasChange3) { cushionColor.TestReportFile3 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoCushionColor.TestReportFile_NewFile3, dtoCushionColor.TestReportFile3); } if (id <= 0) { // Generate code. using (var trans = context.Database.BeginTransaction()) { context.Database.ExecuteSqlCommand("SELECT * FROM CushionColor WITH (TABLOCKX, HOLDLOCK)"); try { var newCode = context.CushionColorMng_function_GenerateCode().FirstOrDefault(); if (!"**".Equals(newCode)) { cushionColor.CushionColorUD = newCode; context.SaveChanges(); } else { notification.Type = NotificationType.Error; notification.Message = "Auto generated code exceed maximum option: [ZZ]"; } } catch (Exception ex) { trans.Rollback(); throw ex; } finally { trans.Commit(); } } } else { context.CushionColorProductGroup.Local.Where(o => o.CushionColor == null).ToList().ForEach(o => context.CushionColorProductGroup.Remove(o)); context.CushionColorTestReport.Local.Where(o => o.CushionColor == null).ToList().ForEach(o => context.CushionColorTestReport.Remove(o)); context.SaveChanges(); } // Handle notification missing information. string emailSubject = (id == 0) ? "TASK REQUEST [CREATE CUSHION COLOR]" : "TASK REQUEST [UPDATE CUSHION COLOR]"; string emailBody = string.Empty; if (!IsNullPropertiesCushionColor(cushionColor, ref emailBody)) { SendToEmailNotification(context, emailSubject, emailBody); } dtoItem = GetData(cushionColor.CushionColorID, out notification).Data; return(true); } } } catch (DataException exData) { notification.Type = NotificationType.Error; ErrorHelper.DataExceptionParser(exData, out number, out indexName); if (number == 2601 && !string.IsNullOrEmpty(indexName)) { if ("CushionColorUDUnique".Equals(indexName)) { notification.Message = "The Cushion Color Code is already exists."; } } else { notification.Message = exData.Message; } return(false); } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = ex.Message; return(false); } //notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; //try //{ // using (CushionColorMngEntities context = CreateContext()) // { // CushionColor dbItem = null; // if (id == 0) // { // dbItem = new CushionColor(); // context.CushionColor.Add(dbItem); // } // else // { // dbItem = context.CushionColor.FirstOrDefault(o => o.CushionColorID == id); // } // if (dbItem == null) // { // notification.Message = "CushionColor not found!"; // return false; // } // else // { // // check concurrency // if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String))) // { // throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT); // } // converter.DTO2BD(dtoItem, ref dbItem); // context.SaveChanges(); // // processing image // if (dtoItem.ImageFile_HasChange) // { // dbItem.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.ImageFile_NewFile, dtoItem.ImageFile); // } // // processing test report file 1 // if (dtoItem.TestReportFile_HasChange1) // { // dbItem.TestReportFile1 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.TestReportFile_NewFile1, dtoItem.TestReportFile1); // } // // processing test report file 2 // if (dtoItem.TestReportFile_HasChange2) // { // dbItem.TestReportFile2 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.TestReportFile_NewFile2, dtoItem.TestReportFile2); // } // // processing test report file 3 // if (dtoItem.TestReportFile_HasChange3) // { // dbItem.TestReportFile3 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.TestReportFile_NewFile3, dtoItem.TestReportFile3); // } // context.SaveChanges(); // dtoItem = GetData(dbItem.CushionColorID, out notification).Data; // return true; // } // } //} //catch (Exception ex) //{ // notification.Type = Library.DTO.NotificationType.Error; // notification.Message = ex.Message; // return false; //} }
public bool AddComment(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.DevRequestHistory dtoDevRequestHistory = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.DevRequestHistory>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (DevRequestMngEntities context = CreateContext()) { DevRequestHistory dbItem = null; DevRequest dbRequest = context.DevRequest.FirstOrDefault(o => o.DevRequestID == id); if (dbRequest != null) { dbItem = new DevRequestHistory(); dbRequest.DevRequestHistory.Add(dbItem); } else { notification.Message = "Dev request not found!"; return(false); } dbItem.Comment = dtoDevRequestHistory.Comment; dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; dbItem.ActionDescription = "ADD COMMENT"; dbItem.DevRequestHistoryActionID = 3; // 3 = ADD COMMENT // request file string TmpFile = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; foreach (DTO.DevRequestCommentAttachedFile dtoFile in dtoDevRequestHistory.DevRequestCommentAttachedFiles.Where(o => o.HasChanged == true)) { // add file DevRequestCommentAttachedFile dbFile = new DevRequestCommentAttachedFile(); dbItem.DevRequestCommentAttachedFile.Add(dbFile); AutoMapper.Mapper.Map <DTO.DevRequestCommentAttachedFile, DevRequestCommentAttachedFile>(dtoFile, dbFile); dbFile.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoFile.NewFile, dtoFile.FileUD, dtoFile.FriendlyName); } // send notify email string emailSubject = "TASK REQUEST: [COMMENT] " + dbRequest.Title; string emailBody = ""; emailBody += "ID: " + dbRequest.DevRequestID.ToString() + "<br/>"; emailBody += "TITLE: " + dbRequest.Title + "<br/>"; emailBody += "UPDATOR: " + supportFactory.GetUsers().FirstOrDefault(o => o.UserId == userId).FullName + "<br/>"; emailBody += "COMMENT: " + dbItem.Comment + "<br/>"; SendNotification(context, dbRequest, emailSubject, emailBody); context.SaveChanges(); dtoItem = GetData(id, out notification).Data; return(true); } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }
public void DTO2BD(DTO.CushionColor dtoItem, string tempFolder, ref CushionColor dbItem) { AutoMapper.Mapper.Map <DTO.CushionColor, CushionColor>(dtoItem, dbItem); dbItem.UpdatedDate = DateTime.Now; // Tri // Add created Cushion Color if (dtoItem.CushionColorID == 0) { dbItem.CreatedBy = dtoItem.CreatedBy; dbItem.CreatedDate = DateTime.Now; } // map child if (dtoItem.CushionColorProductGroups != null) { // map child rows foreach (DTO.CushionColorProductGroup dtoGroup in dtoItem.CushionColorProductGroups) { CushionColorProductGroup dbGroup; if (dtoGroup.CushionColorProductGroupID <= 0) { dbGroup = new CushionColorProductGroup(); dbItem.CushionColorProductGroup.Add(dbGroup); } else { dbGroup = dbItem.CushionColorProductGroup.FirstOrDefault(o => o.CushionColorProductGroupID == dtoGroup.CushionColorProductGroupID); } if (dbGroup != null) { AutoMapper.Mapper.Map <DTO.CushionColorProductGroup, CushionColorProductGroup>(dtoGroup, dbGroup); } } } // Mapping cushion color test report if (dtoItem.CushionColorTestReports != null) { foreach (var item in dbItem.CushionColorTestReport.ToArray()) { if (!dtoItem.CushionColorTestReports.Select(s => s.CushionColorTestReportID).Contains(item.CushionColorTestReportID)) { dbItem.CushionColorTestReport.Remove(item); } } Framework.DAL.DataFactory fwFactory = new Framework.DAL.DataFactory(); // Mapping cushion color test report rows foreach (DTO.CushionColorTestReport dtoCushionColorTestReport in dtoItem.CushionColorTestReports) { CushionColorTestReport dbCushionColorTestReport; if (dtoCushionColorTestReport.CushionColorTestReportID <= 0) { dbCushionColorTestReport = new CushionColorTestReport(); dbItem.CushionColorTestReport.Add(dbCushionColorTestReport); } else { dbCushionColorTestReport = dbItem.CushionColorTestReport.FirstOrDefault(o => o.CushionColorTestReportID == dtoCushionColorTestReport.CushionColorTestReportID); } if (dbCushionColorTestReport != null) { Mapper.Map <DTO.CushionColorTestReport, CushionColorTestReport>(dtoCushionColorTestReport, dbCushionColorTestReport); if (dtoCushionColorTestReport.File_HasChange.HasValue && dtoCushionColorTestReport.File_HasChange.Value) { dbCushionColorTestReport.FileUD = fwFactory.CreateNoneImageFilePointer(tempFolder, dtoCushionColorTestReport.File_NewFile, dtoCushionColorTestReport.FileUD); } } } } }