public void DTO2DB(DTO.CatalogFileDTO dtoItem, ref CatalogFile dbItem, string TmpFile, int userId) { // employee AutoMapper.Mapper.Map <DTO.CatalogFileDTO, CatalogFile>(dtoItem, dbItem); if (dtoItem.HasChanged) { dbItem.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoItem.NewFile, dbItem.FileUD, dtoItem.FriendlyName); } if (dtoItem.PLHasChanged) { dbItem.PriceListFileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoItem.PLNewFile, dbItem.PriceListFileUD, dtoItem.PLFriendlyName); } }
public void DTO2DB(DTO.UserProfile dtoItem, ref Employee dbItem, string TmpFile, int userId) { // employee AutoMapper.Mapper.Map <DTO.UserProfile, Employee>(dtoItem, dbItem); if (!string.IsNullOrEmpty(dtoItem.DateOfBirth)) { if (DateTime.TryParse(dtoItem.DateOfBirth, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { dbItem.DateOfBirth = tmpDate; } } if (!string.IsNullOrEmpty(dtoItem.DateStart)) { if (DateTime.TryParse(dtoItem.DateStart, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { dbItem.DateStart = tmpDate; } } if (dtoItem.HasChanged) { dbItem.PersonalPhoto = fwFactory.CreateFilePointer(TmpFile, dtoItem.NewFile, dbItem.PersonalPhoto); } if (dtoItem.CVHasChanged) { dbItem.ResumeFile = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoItem.CVNewFile, dbItem.ResumeFile, dtoItem.CVFileName); } foreach (DTO.EmployeeFactory dtoFactory in dtoItem.EmployeeFactories) { EmployeeFactory dbFactory = dbItem.EmployeeFactory.FirstOrDefault(o => o.EmployeeFactoryID == dtoFactory.EmployeeFactoryID); AutoMapper.Mapper.Map <DTO.EmployeeFactory, EmployeeFactory>(dtoFactory, dbFactory); } }
public void DTO2DB(DTO.OnlineFile dtoItem, ref OnlineFile dbItem, string TmpFile, int userId) { // file info AutoMapper.Mapper.Map <DTO.OnlineFile, OnlineFile>(dtoItem, dbItem); dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; // processing file if (dtoItem.HasChanged) { dbItem.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoItem.NewFile, dtoItem.FileUD, dtoItem.FriendlyName); } // file permission if (dtoItem.OnlineFilePermissions != null) { foreach (OnlineFilePermission dbPermission in dbItem.OnlineFilePermission.ToArray()) { if (!dtoItem.OnlineFilePermissions.Select(o => o.OnlineFilePermissionID).Contains(dbPermission.OnlineFilePermissionID)) { dbItem.OnlineFilePermission.Remove(dbPermission); } } foreach (DTO.OnlineFilePermission dtoPermission in dtoItem.OnlineFilePermissions.Where(o => o.OnlineFilePermissionID <= 0)) { OnlineFilePermission dbPermission = new OnlineFilePermission(); dbItem.OnlineFilePermission.Add(dbPermission); AutoMapper.Mapper.Map <DTO.OnlineFilePermission, OnlineFilePermission>(dtoPermission, dbPermission); } } }
public DTO.SaleOrder UploadClientPOFile(int saleOrderID, string newFile, string oldPointer, string tempFolder, out Library.DTO.Notification notification) { Module.Framework.DAL.DataFactory framework_factory = new Module.Framework.DAL.DataFactory(); DTO.SaleOrder dtoSaleOrder = new DTO.SaleOrder(); notification = new Library.DTO.Notification { Type = Library.DTO.NotificationType.Success, Message = "Upload success" }; try { using (SaleOrderMngEntities context = CreateContext()) { string newPointer = framework_factory.CreateNoneImageFilePointer(tempFolder, newFile, oldPointer); if (saleOrderID > 0) { var saleOrder = context.SaleOrder.Where(o => o.SaleOrderID == saleOrderID).FirstOrDefault(); saleOrder.ClientPOFile = newPointer; context.SaveChanges(); //get return data dtoSaleOrder = GetBackData(saleOrderID, out notification); } } return(dtoSaleOrder); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { notification.DetailMessage.Add(ex.InnerException.Message); } return(dtoSaleOrder); } }
private void cmdImportToFilesTable_Click(object sender, EventArgs e) { Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); foreach (FileInfo fInfo in (new DirectoryInfo(txtFolderToImport.Text)).GetFiles()) { fwFactory.CreateNoneImageFilePointer(txtFolderToImport.Text, fInfo.Name, string.Empty); } }
public void DTO2DB_InternalRemark(DTO.InternalRemark.RemarkDTO dtoItem, ref SampleRemark dbItem, string TmpFile) { AutoMapper.Mapper.Map <DTO.InternalRemark.RemarkDTO, SampleRemark>(dtoItem, dbItem); // remark image foreach (SampleRemarkImage dbImage in dbItem.SampleRemarkImage.ToArray()) { if (!dtoItem.RemarkImageDTOs.Select(o => o.SampleRemarkImageID).Contains(dbImage.SampleRemarkImageID)) { // delete files if (!string.IsNullOrEmpty(dbImage.FileUD)) { fwFactory.RemoveImageFile(dbImage.FileUD); } dbItem.SampleRemarkImage.Remove(dbImage); } } foreach (DTO.InternalRemark.RemarkImageDTO dtoImage in dtoItem.RemarkImageDTOs) { SampleRemarkImage dbImage; if (dtoImage.SampleRemarkImageID <= 0) { dbImage = new SampleRemarkImage(); dbItem.SampleRemarkImage.Add(dbImage); } else { dbImage = dbItem.SampleRemarkImage.FirstOrDefault(o => o.SampleRemarkImageID == dtoImage.SampleRemarkImageID); } if (dbItem != null) { AutoMapper.Mapper.Map <DTO.InternalRemark.RemarkImageDTO, SampleRemarkImage>(dtoImage, dbImage); if (dtoImage.HasChanged && !string.IsNullOrEmpty(dtoImage.NewFile)) { dbImage.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoImage.NewFile, dbImage.FileUD, dtoImage.FriendlyName); } } } }
public override bool UpdateData(int id, ref DTO.ForwarderInvoiceMng.ForwarderInvoice dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (ForwarderInvoiceMngEntities context = CreateContext()) { ForwarderInvoice dbItem = null; if (id == 0) { dbItem = new ForwarderInvoice(); context.ForwarderInvoices.Add(dbItem); } else { dbItem = context.ForwarderInvoices.FirstOrDefault(o => o.ForwarderInvoiceID == id); } if (dbItem == null) { notification.Message = "Forwarder Invoice not found"; return(false); } else { converter.DTO2BD(dtoItem, ref dbItem); context.SaveChanges(); // processing file if (dtoItem.PDFFileScan_HasChange) { dbItem.PDFFileScan = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.PDFFileScan_NewFile, dtoItem.PDFFileScan); } context.SaveChanges(); dtoItem = GetData(dbItem.ForwarderInvoiceID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public void DTO2DB(DTO.UserProfile dtoItem, ref Employee dbItem, string TmpFile, int userId) { AutoMapper.Mapper.Map <DTO.UserProfile, Employee>(dtoItem, dbItem); if (!string.IsNullOrEmpty(dtoItem.DateOfBirth)) { if (DateTime.TryParse(dtoItem.DateOfBirth, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { dbItem.DateOfBirth = tmpDate; } } if (dtoItem.HasChanged) { dbItem.PersonalPhoto = fwFactory.CreateFilePointer(TmpFile, dtoItem.NewFile, dbItem.PersonalPhoto); } if (dtoItem.CVHasChanged) { dbItem.ResumeFile = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoItem.CVNewFile, dbItem.ResumeFile, dtoItem.CVFileName); } if (dtoItem.SignatureHasChanged) { dbItem.SignatureFile = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoItem.SignatureNewFile, dbItem.SignatureFile, dtoItem.SignatureFileName); } }
public void DTO2DB(DTO.DevRequest dtoItem, ref DevRequest dbItem, string TmpFile, int userId) { // request AutoMapper.Mapper.Map <DTO.DevRequest, DevRequest>(dtoItem, dbItem); // request file foreach (DTO.DevRequestFile dtoFile in dtoItem.DevRequestFiles.Where(o => o.HasChanged == true)) { // add file DevRequestFile dbFile = new DevRequestFile(); dbItem.DevRequestFile.Add(dbFile); AutoMapper.Mapper.Map <DTO.DevRequestFile, DevRequestFile>(dtoFile, dbFile); dbFile.FileUD = fwFactory.CreateNoneImageFilePointer(TmpFile, dtoFile.NewFile, dtoFile.FileUD, dtoFile.FriendlyName); } }
public void DTO2BD_Forwarder(DTO.ForwarderMng.Forwarder dtoItem, ref Forwarder dbItem, string tempFolder) { if (dtoItem.ForwarderImages != null) { foreach (var item in dbItem.ForwarderImage.ToArray()) { if (!dtoItem.ForwarderImages.Select(s => s.ForwarderImageID).Contains(item.ForwarderImageID)) { dbItem.ForwarderImage.Remove(item); } } foreach (var dto in dtoItem.ForwarderImages) { ForwarderImage item; if (dto.ForwarderImageID < 0) { item = new ForwarderImage(); dbItem.ForwarderImage.Add(item); } else { item = dbItem.ForwarderImage.FirstOrDefault(s => s.ForwarderImageID == dto.ForwarderImageID); } if (item != null) { AutoMapper.Mapper.Map <DTO.ForwarderMng.ForwarderImage, ForwarderImage>(dto, item); if (dto.File_HasChange.HasValue && dto.File_HasChange.Value) { Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); item.FileUD = fwFactory.CreateNoneImageFilePointer(tempFolder, dto.File_NewFile, dto.FileUD); } } } } if (dtoItem.ForwarderPICs != null) { foreach (var item1 in dbItem.ForwarderPIC.ToArray()) { if (!dtoItem.ForwarderPICs.Select(s => s.ForwarderPICID).Contains(item1.ForwarderPICID)) { dbItem.ForwarderPIC.Remove(item1); } } foreach (var dto1 in dtoItem.ForwarderPICs) { ForwarderPIC item1; if (dto1.ForwarderPICID < 0) { item1 = new ForwarderPIC(); dbItem.ForwarderPIC.Add(item1); } else { item1 = dbItem.ForwarderPIC.FirstOrDefault(s => s.ForwarderPICID == dto1.ForwarderPICID); } if (item1 != null) { AutoMapper.Mapper.Map <DTO.ForwarderMng.ForwarderPIC, ForwarderPIC>(dto1, item1); } } } AutoMapper.Mapper.Map <DTO.ForwarderMng.Forwarder, Forwarder>(dtoItem, dbItem); }
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 override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification) { DTO.FactorySalesOrderDTO dtoFactorySaleOrder = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactorySalesOrderDTO>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { // Validation for input ValidationContext validationDTO = new ValidationContext(dtoFactorySaleOrder, null, null); List <ValidationResult> results = new List <ValidationResult>(); bool valid = Validator.TryValidateObject(dtoFactorySaleOrder, validationDTO, results, true); if (!valid) { string error = ""; List <string> detailError = new List <string>(); foreach (ValidationResult vr in results) { notification.Type = NotificationType.Error; error = vr.ErrorMessage; notification.Message = "Value not valid"; return(false); } } using (FactorySalesOrderMngEntities context = CreateContext()) { //var lstSaleQuotation = converter.GetListFactorySaleQuotation(context.FactorySaleOrderMng_ListFactorySaleQuotion_View.ToList()); //var existQuotation = lstSaleQuotation.Where(x => x.FactorySaleQuotationID == dtoFactorySaleOrder.FactorySaleQuotationID && x.FactorySaleQuotationUD == dtoFactorySaleOrder.FactorySaleQuotationUD).FirstOrDefault(); //if (existQuotation == null) //{ // notification.Type = NotificationType.Error; // notification.Message = "Sales Quotation Code not exist"; // return false; //} var lstcustomer = converter.GetListRawMaterial(context.FactorySaleQuotationMng_FactorySaleQuotation_ListRawMaterial_View.ToList()); var existcustomer = lstcustomer.Where(x => x.FactoryRawMaterialID == dtoFactorySaleOrder.FactoryRawMaterialID && x.FactoryRawMaterialShortNM == dtoFactorySaleOrder.FactoryRawMaterialShortNM).FirstOrDefault(); if (existcustomer == null) { notification.Type = NotificationType.Error; notification.Message = "Customer not exist"; return(false); } //var existClientContact = converter.GetListClientContact(context.FactorySaleQuotationMng_FactorySaleQuotation_ClientContact_View.ToList()); //var existClientContacts = existClientContact.Where(x => x.FullName == dtoFactorySaleOrder.FactoryRawMaterialContactPersonNM).FirstOrDefault(); //if (existClientContacts == null) //{ // notification.Type = NotificationType.Error; // notification.Message = "Contact Person Name not exist"; // return false; //} //var existEmp = converter.GetListListEmployee(context.FactorySaleQuotationMng_Employee_View.ToList()); //var existEmps = existEmp.Where(x => x.EmployeeNM == dtoFactorySaleOrder.EmployeeNM).FirstOrDefault(); //if (existEmps == null) //{ // notification.Type = NotificationType.Error; // notification.Message = "Employee Name not exist"; // return false; //} //List<DTO.ProductionItem> data = new List<DTO.ProductionItem>(); //var lstchhooseProId = dtoFactorySaleOrder.LstFactorySaleOrderDetail.Select(x => x.ProductionItemID).ToList(); //if(lstchhooseProId == null || lstchhooseProId.Count <= 0) //{ // notification.Type = NotificationType.Error; // notification.Message = "Please choose at least one product Product"; // return false; //} var lstProDB = converter.GetListListProductionItem(context.FactorySaleQuotationMng_FactorySaleQuotation_ListProductionItem_View.Where(o => o.ProductionItemNM != null).ToList()); var lstchhooseProName = dtoFactorySaleOrder.LstFactorySaleOrderDetail.Select(x => x.ProductionItemNM).ToList(); if (lstchhooseProName != null && lstchhooseProName.Count > 0) { if (lstProDB != null && lstProDB.Count > 0) { foreach (var item in lstchhooseProName) { var existProductName = lstProDB.Where(x => x.ProductionItemNM.Contains(item)).FirstOrDefault(); if (existProductName == null) { notification.Type = NotificationType.Error; notification.Message = "Product Name not exist"; return(false); } } } } if (notification.Type == NotificationType.Error) { return(false); } ///end validation FactorySaleOrder dbItem = null; if (id == 0) { dbItem = new FactorySaleOrder(); context.FactorySaleOrder.Add(dbItem); } else { dbItem = context.FactorySaleOrder.FirstOrDefault(o => o.FactorySaleOrderID == id); } // process Attached files foreach (FactorySalesOrderAttachedFileDTO dtoattachedFile in dtoFactorySaleOrder.LstFactorySaleOrderAttachedFile) { if (dtoattachedFile.OtherFileHasChange) { if (string.IsNullOrEmpty(dtoattachedFile.NewOtherFile)) { fwFactory.RemoveFile(dtoattachedFile.OtherFile); } else { dtoattachedFile.FileUD = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoattachedFile.NewOtherFile, dtoattachedFile.OtherFile, dtoattachedFile.OtherFileFriendlyName); } } } if (dbItem == null) { notification.Message = "Factory Sale Order not found!"; return(false); } else { var userInformation = _AccountMngFactory.GetUserInformation(userId, out notification); ///convert dto to db converter.updateFactorySaleOrder(dtoFactorySaleOrder, ref dbItem); context.FactorySaleOrderDetail.Local.Where(o => o.FactorySaleOrder == null).ToList().ForEach(o => context.FactorySaleOrderDetail.Remove(o)); dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = userId; dbItem.FactorySaleOrderStatusID = 1; dbItem.DocumentDate = dtoFactorySaleOrder.DocumentDate.ConvertStringToDateTime(); dbItem.ExpectedPaidDate = dtoFactorySaleOrder.ExpectedPaidDate.ConvertStringToDateTime(); dbItem.CreatedDate = dtoFactorySaleOrder.CreatedDate.ConvertStringToDateTime(); dbItem.ValidUntil = dtoFactorySaleOrder.ValidUntil.ConvertStringToDateTime(); if (userInformation != null) { dbItem.CompanyID = userInformation.CompanyID; } context.SaveChanges(); // Generate FactorySaleOrderUD. if (id == 0) { context.FactorySaleOrderMng_function_GenerateFactorySaleOrderUD(dbItem.FactorySaleOrderID, dbItem.CreatedDate.Value.Year, dbItem.CreatedDate.Value.Month); } context.SaveChanges(); dtoItem = GetData(userId, dbItem.FactorySaleOrderID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Message = ex.Message; notification.Type = Library.DTO.NotificationType.Error; return(false); } }
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.FactorySaleQuotationDTO dtoFactorySaleQuotation = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactorySaleQuotationDTO>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { if (dtoFactorySaleQuotation.FactoryRawMaterialID == null) { notification.Type = NotificationType.Error; notification.Message = "Customer not exist"; return(false); } using (FactorySalesQuotationMngEntities context = CreateContext()) { FactorySaleQuotation dbItem = null; if (id == 0) { dbItem = new FactorySaleQuotation(); context.FactorySaleQuotation.Add(dbItem); } else { dbItem = context.FactorySaleQuotation.FirstOrDefault(o => o.FactorySaleQuotationID == id); } // process Attached files foreach (FactorySaleQuotationAttachedFileDTO dtoattachedFile in dtoFactorySaleQuotation.LstFactorySaleQuotationAttachedFile) { if (dtoattachedFile.OtherFileHasChange) { if (string.IsNullOrEmpty(dtoattachedFile.NewOtherFile)) { fwFactory.RemoveFile(dtoattachedFile.OtherFile); } else { dtoattachedFile.FileUD = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoattachedFile.NewOtherFile, dtoattachedFile.OtherFile, dtoattachedFile.OtherFileFriendlyName); } } } if (dbItem == null) { notification.Message = "Factory Sale Quotation not found!"; return(false); } else { ///convert dto to db var userInformation = _AccountMngFactory.GetUserInformation(userId, out notification); converter.updateFactorySaleQuotation(dtoFactorySaleQuotation, ref dbItem); context.FactorySaleQuotationDetail.Local.Where(o => o.FactorySaleQuotation == null).ToList().ForEach(o => context.FactorySaleQuotationDetail.Remove(o)); context.FactorySaleQuotationAttachedFile.Local.Where(o => o.FactorySaleQuotation == null).ToList().ForEach(o => context.FactorySaleQuotationAttachedFile.Remove(o)); dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = userId; dbItem.FactorySaleQuotationStatusID = 1; dbItem.DocumentDate = dtoFactorySaleQuotation.DocumentDate.ConvertStringToDateTime(); dbItem.ExpectedPaidDate = dtoFactorySaleQuotation.ExpectedPaidDate.ConvertStringToDateTime(); dbItem.CreatedDate = dtoFactorySaleQuotation.CreatedDate.ConvertStringToDateTime(); dbItem.ValidUntil = dtoFactorySaleQuotation.ValidUntil.ConvertStringToDateTime(); if (userInformation != null) { dbItem.CompanyID = userInformation.CompanyID; } // Generate FactorySaleQuotationUD. if (id == 0) { dbItem.FactorySaleQuotationUD = context.FactorySaleQuotationMng_function_GenerateFactorySaleQuotationUD(dbItem.CreatedDate.Value.Year, dbItem.CreatedDate.Value.Month).FirstOrDefault(); } context.SaveChanges(); dtoItem = GetData(userId, dbItem.FactorySaleQuotationID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Message = ex.Message; notification.Type = Library.DTO.NotificationType.Error; return(false); } }
public override bool UpdateData(int id, ref DTO.FactoryProformaInvoiceMng.FactoryProformaInvoice dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (FactoryProformaInvoiceMngEntities context = CreateContext()) { FactoryProformaInvoice dbItem = null; if (id == 0) { dbItem = new FactoryProformaInvoice(); context.FactoryProformaInvoice.Add(dbItem); } else { dbItem = context.FactoryProformaInvoice.FirstOrDefault(o => o.FactoryProformaInvoiceID == id); } if (dbItem == null) { notification.Message = "Factory proforma invoice not found!"; return(false); } else { // check if detail is valid int factoryOrderID = dtoItem.FactoryOrderID.Value; var dtoCheckInfo = context.FactoryProformaInvoiceMng_FactoryOrderInfo_View.Where(o => o.FactoryOrderID == factoryOrderID).ToList(); foreach (DTO.FactoryProformaInvoiceMng.FactoryProformaInvoiceDetail dtoDetail in dtoItem.Details) { if (dtoDetail.FactoryOrderDetailID.HasValue && dtoDetail.FactoryOrderDetailID > 0 && dtoCheckInfo.Count(o => o.FactoryOrderDetailID == dtoDetail.FactoryOrderDetailID.Value) == 0) { throw new Exception("Invalid detail: " + dtoDetail.ArticleCode + " not exists in factory order " + dtoItem.FactoryUD + " !"); } } // 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.FactoryProformaInvoiceDetail.Local.Where(o => o.FactoryProformaInvoice == null).ToList().ForEach(o => context.FactoryProformaInvoiceDetail.Remove(o)); context.SaveChanges(); // processing file if (dtoItem.AttachedFile_HasChange) { dbItem.AttachedFile = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.AttachedFile_NewFile, dtoItem.AttachedFile); } context.SaveChanges(); dtoItem = GetData(dtoItem.UpdatedBy.Value, dbItem.FactoryProformaInvoiceID, 0, string.Empty, 0, 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 id, ref DTO.CushionColorMng.CushionColor dtoItem, out Library.DTO.Notification notification) { notification = new Notification(); notification.Type = NotificationType.Success; int number; string indexName; try { using (var context = CreateContext()) { CushionColor cushionColor = null; if (id == 0) { cushionColor = new CushionColor(); context.CushionColor.Add(cushionColor); } else { 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(dtoItem.ConcurrencyFlag_String))) { notification.Type = NotificationType.Error; notification.Message = Library.Helper.TEXT_CONCURRENCY_CONFLICT; return(false); } converter.DTO2BD(dtoItem, _TempFolder, ref cushionColor); // processing image if (dtoItem.ImageFile_HasChange) { cushionColor.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.ImageFile_NewFile, dtoItem.ImageFile); } // processing test report file 1 if (dtoItem.TestReportFile_HasChange1) { cushionColor.TestReportFile1 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.TestReportFile_NewFile1, dtoItem.TestReportFile1); } // processing test report file 2 if (dtoItem.TestReportFile_HasChange2) { cushionColor.TestReportFile2 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.TestReportFile_NewFile2, dtoItem.TestReportFile2); } // processing test report file 3 if (dtoItem.TestReportFile_HasChange3) { cushionColor.TestReportFile3 = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.TestReportFile_NewFile3, dtoItem.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 = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.HandleExceptionSingleLine(ex, ds); 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 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.Factory dtoItem, ref Factory dbItem, int userId) { // FactoryImage if (dtoItem.FactoryImages != null) { foreach (var item in dbItem.FactoryImage.ToArray()) { if (!dtoItem.FactoryImages.Select(o => o.FactoryImageID).Contains(item.FactoryImageID)) { dbItem.FactoryImage.Remove(item); } } //map child row foreach (var item in dtoItem.FactoryImages) { FactoryImage dbFactoryImage; if (item.FactoryImageID <= 0) { dbFactoryImage = new FactoryImage(); dbItem.FactoryImage.Add(dbFactoryImage); } else { dbFactoryImage = dbItem.FactoryImage.FirstOrDefault(o => o.FactoryImageID == item.FactoryImageID); } if (dbFactoryImage != null) { AutoMapper.Mapper.Map <DTO.FactoryImage, FactoryImage>(item, dbFactoryImage); } } } // Business Card if (dtoItem.FactoryBusinessCard != null) { foreach (var item in dbItem.FactoryBusinessCard.ToArray()) { if (!dtoItem.FactoryBusinessCard.Select(o => o.FactoryBusinessCardID).Contains(item.FactoryBusinessCardID)) { dbItem.FactoryBusinessCard.Remove(item); } } //map child row foreach (var item in dtoItem.FactoryBusinessCard) { FactoryBusinessCard dbFactoryBusinessCard; if (item.FactoryBusinessCardID <= 0) { dbFactoryBusinessCard = new FactoryBusinessCard(); dbItem.FactoryBusinessCard.Add(dbFactoryBusinessCard); } else { dbFactoryBusinessCard = dbItem.FactoryBusinessCard.FirstOrDefault(o => o.FactoryBusinessCardID == item.FactoryBusinessCardID); } if (dbFactoryBusinessCard != null) { AutoMapper.Mapper.Map <DTO.FactoryBusinessCard, FactoryBusinessCard>(item, dbFactoryBusinessCard); } } } // FactoryDirector if (dtoItem.FactoryDirectors != null) { foreach (var item in dbItem.FactoryDirector.ToArray()) { if (!dtoItem.FactoryDirectors.Select(o => o.FactoryDirectorID).Contains(item.FactoryDirectorID)) { dbItem.FactoryDirector.Remove(item); } } //map child row foreach (var item in dtoItem.FactoryDirectors) { FactoryDirector dbFactoryDirector; if (item.FactoryDirectorID <= 0) { dbFactoryDirector = new FactoryDirector(); dbItem.FactoryDirector.Add(dbFactoryDirector); } else { dbFactoryDirector = dbItem.FactoryDirector.FirstOrDefault(o => o.FactoryDirectorID == item.FactoryDirectorID); } if (dbFactoryDirector != null) { AutoMapper.Mapper.Map <DTO.FactoryDirector, FactoryDirector>(item, dbFactoryDirector); } } } // FactoryManager if (dtoItem.FactoryManagers != null) { foreach (var item in dbItem.FactoryManager.ToArray()) { if (!dtoItem.FactoryManagers.Select(o => o.FactoryManagerID).Contains(item.FactoryManagerID)) { dbItem.FactoryManager.Remove(item); } } //map child row foreach (var item in dtoItem.FactoryManagers) { FactoryManager dbFactoryManager; if (item.FactoryManagerID <= 0) { dbFactoryManager = new FactoryManager(); dbItem.FactoryManager.Add(dbFactoryManager); } else { dbFactoryManager = dbItem.FactoryManager.FirstOrDefault(o => o.FactoryManagerID == item.FactoryManagerID); } if (dbFactoryManager != null) { AutoMapper.Mapper.Map <DTO.FactoryManager, FactoryManager>(item, dbFactoryManager); } } } // FactoryPricing if (dtoItem.FactoryPricings != null) { foreach (var item in dbItem.FactoryPricing.ToArray()) { if (!dtoItem.FactoryPricings.Select(o => o.FactoryPricingID).Contains(item.FactoryPricingID)) { dbItem.FactoryPricing.Remove(item); } } //map child row foreach (var item in dtoItem.FactoryPricings) { FactoryPricing dbFactoryPricing; if (item.FactoryPricingID <= 0) { dbFactoryPricing = new FactoryPricing(); dbItem.FactoryPricing.Add(dbFactoryPricing); } else { dbFactoryPricing = dbItem.FactoryPricing.FirstOrDefault(o => o.FactoryPricingID == item.FactoryPricingID); } if (dbFactoryPricing != null) { AutoMapper.Mapper.Map <DTO.FactoryPricing, FactoryPricing>(item, dbFactoryPricing); } } } // FactorySampleTechnical if (dtoItem.FactorySampleTechnicals != null) { foreach (var item in dbItem.FactorySampleTechnical.ToArray()) { if (!dtoItem.FactorySampleTechnicals.Select(o => o.FactorySampleTechnicalID).Contains(item.FactorySampleTechnicalID)) { dbItem.FactorySampleTechnical.Remove(item); } } //map child row foreach (var item in dtoItem.FactorySampleTechnicals) { FactorySampleTechnical dbFactorySampleTechnical; if (item.FactorySampleTechnicalID <= 0) { dbFactorySampleTechnical = new FactorySampleTechnical(); dbItem.FactorySampleTechnical.Add(dbFactorySampleTechnical); } else { dbFactorySampleTechnical = dbItem.FactorySampleTechnical.FirstOrDefault(o => o.FactorySampleTechnicalID == item.FactorySampleTechnicalID); } if (dbFactorySampleTechnical != null) { AutoMapper.Mapper.Map <DTO.FactorySampleTechnical, FactorySampleTechnical>(item, dbFactorySampleTechnical); } } } // FactoryResponsiblePerson if (dtoItem.FactoryResponsiblePersons != null) { foreach (var item in dbItem.FactoryResponsiblePerson.ToArray()) { if (!dtoItem.FactoryResponsiblePersons.Select(o => o.FactoryResponsiblePersonID).Contains(item.FactoryResponsiblePersonID)) { dbItem.FactoryResponsiblePerson.Remove(item); } } //map child row foreach (var item in dtoItem.FactoryResponsiblePersons) { FactoryResponsiblePerson dbFactoryResponsiblePerson; if (item.FactoryResponsiblePersonID <= 0) { dbFactoryResponsiblePerson = new FactoryResponsiblePerson(); dbItem.FactoryResponsiblePerson.Add(dbFactoryResponsiblePerson); } else { dbFactoryResponsiblePerson = dbItem.FactoryResponsiblePerson.FirstOrDefault(o => o.FactoryResponsiblePersonID == item.FactoryResponsiblePersonID); } if (dbFactoryResponsiblePerson != null) { AutoMapper.Mapper.Map <DTO.FactoryResponsiblePerson, FactoryResponsiblePerson>(item, dbFactoryResponsiblePerson); } } } // FactoryRawMaterialSupplier if (dtoItem.FactoryRawMaterialSuppliers != null) { foreach (var item in dbItem.FactoryRawMaterialSupplier.ToArray()) { if (!dtoItem.FactoryRawMaterialSuppliers.Select(o => o.FactoryRawMaterialSupplierID).Contains(item.FactoryRawMaterialSupplierID)) { dbItem.FactoryRawMaterialSupplier.Remove(item); } } //map child row foreach (var item in dtoItem.FactoryRawMaterialSuppliers) { FactoryRawMaterialSupplier dbFactoryRawMaterialSupplier; if (item.FactoryRawMaterialSupplierID <= 0) { dbFactoryRawMaterialSupplier = new FactoryRawMaterialSupplier(); dbItem.FactoryRawMaterialSupplier.Add(dbFactoryRawMaterialSupplier); } else { dbFactoryRawMaterialSupplier = dbItem.FactoryRawMaterialSupplier.FirstOrDefault(o => o.FactoryRawMaterialSupplierID == item.FactoryRawMaterialSupplierID); } if (dbFactoryRawMaterialSupplier != null) { AutoMapper.Mapper.Map <DTO.FactoryRawMaterialSupplier, FactoryRawMaterialSupplier>(item, dbFactoryRawMaterialSupplier); } } } // FactoryInHouseTest if (dtoItem.FactoryInHouseTests != null) { foreach (var item in dbItem.FactoryInHouseTest.ToArray()) { if (!dtoItem.FactoryInHouseTests.Select(o => o.FactoryInHouseTestID).Contains(item.FactoryInHouseTestID)) { dbItem.FactoryInHouseTest.Remove(item); } } //map child row foreach (var item in dtoItem.FactoryInHouseTests) { FactoryInHouseTest dbFactoryInHouseTest; if (item.FactoryInHouseTestID <= 0) { dbFactoryInHouseTest = new FactoryInHouseTest(); dbItem.FactoryInHouseTest.Add(dbFactoryInHouseTest); } else { dbFactoryInHouseTest = dbItem.FactoryInHouseTest.FirstOrDefault(o => o.FactoryInHouseTestID == item.FactoryInHouseTestID); } if (dbFactoryInHouseTest != null) { AutoMapper.Mapper.Map <DTO.FactoryInHouseTest, FactoryInHouseTest>(item, dbFactoryInHouseTest); } } } // FactoryCertificate if (dtoItem.FactoryCertificates != null) { foreach (var item in dbItem.FactoryCertificate.ToArray()) { if (!dtoItem.FactoryCertificates.Select(o => o.FactoryCertificateID).Contains(item.FactoryCertificateID)) { dbItem.FactoryCertificate.Remove(item); } } //map child row foreach (var item in dtoItem.FactoryCertificates) { FactoryCertificate dbFactoryCertificate; if (item.FactoryCertificateID <= 0) { dbFactoryCertificate = new FactoryCertificate(); dbItem.FactoryCertificate.Add(dbFactoryCertificate); } else { dbFactoryCertificate = dbItem.FactoryCertificate.FirstOrDefault(o => o.FactoryCertificateID == item.FactoryCertificateID); } if (dbFactoryCertificate != null) { AutoMapper.Mapper.Map <DTO.FactoryCertificate, FactoryCertificate>(item, dbFactoryCertificate); dbFactoryCertificate.ValidUntil = item.ValidUntil.ConvertStringToDateTime(); //convert datetime to string } } } // Factory Turnover if (dtoItem.FactoryTurnovers != null) { //map child row foreach (var item in dtoItem.FactoryTurnovers) { FactoryTurnover dbFactoryTurnover; if (item.FactoryTurnoverID <= 0) { dbFactoryTurnover = new FactoryTurnover(); dbItem.FactoryTurnover.Add(dbFactoryTurnover); } else { dbFactoryTurnover = dbItem.FactoryTurnover.FirstOrDefault(o => o.FactoryTurnoverID == item.FactoryTurnoverID); } if (dbFactoryTurnover != null) { AutoMapper.Mapper.Map <DTO.FactoryTurnover, FactoryTurnover>(item, dbFactoryTurnover); } } } // Factory Expected Capacity if (dtoItem.FactoryExpectedCapacities != null) { //map child row foreach (var item in dtoItem.FactoryExpectedCapacities) { FactoryExpectedCapacity dbFactoryExpectedCapacity; if (item.FactoryExpectedCapacityID <= 0) { dbFactoryExpectedCapacity = new FactoryExpectedCapacity(); dbItem.FactoryExpectedCapacity.Add(dbFactoryExpectedCapacity); } else { dbFactoryExpectedCapacity = dbItem.FactoryExpectedCapacity.FirstOrDefault(o => o.FactoryExpectedCapacityID == item.FactoryExpectedCapacityID); } if (dbFactoryExpectedCapacity != null) { AutoMapper.Mapper.Map <DTO.FactoryExpectedCapacity, FactoryExpectedCapacity>(item, dbFactoryExpectedCapacity); } } } // Factory Capacity By Weeks if (dtoItem.factoryCapacityByWeeks != null) { //map child row foreach (var item in dtoItem.factoryCapacityByWeeks) { FactoryCapacity dbFactoryCapacity; if (item.FactoryCapacityID <= 0 && item.Capacity != null) { dbFactoryCapacity = new FactoryCapacity(); dbItem.FactoryCapacity.Add(dbFactoryCapacity); } else { dbFactoryCapacity = dbItem.FactoryCapacity.FirstOrDefault(o => o.FactoryCapacityID == item.FactoryCapacityID); } if (dbFactoryCapacity != null) { AutoMapper.Mapper.Map <DTO.FactoryCapacityByWeek, FactoryCapacity>(item, dbFactoryCapacity); } } } // FactorySupplier //if (dtoItem.FactorySuppliers != null) //{ // foreach (var item in dbItem.FactorySupplier.ToArray()) // { // if (!dtoItem.FactorySuppliers.Select(o => o.FactorySupplierID).Contains(item.FactorySupplierID)) // { // dbItem.FactorySupplier.Remove(item); // } // } // //map child row // foreach (var item in dtoItem.FactorySuppliers) // { // FactorySupplier dbFactorySupplier; // if (item.FactorySupplierID <= 0) // { // dbFactorySupplier = new FactorySupplier(); // dbItem.FactorySupplier.Add(dbFactorySupplier); // } // else // { // dbFactorySupplier = dbItem.FactorySupplier.FirstOrDefault(o => o.FactorySupplierID == item.FactorySupplierID); // } // if (dbFactorySupplier != null) // { // AutoMapper.Mapper.Map<DTO.FactorySupplier, FactorySupplier>(item, dbFactorySupplier); // } // } //} // FactoryGallery for add video 360 if (dtoItem.FactoryGalleries != null) { foreach (FactoryGallery dbFactoryGallery in dbItem.FactoryGallery.ToList()) { if (!dtoItem.FactoryGalleries.Select(s => s.FactoryGalleryID).Contains(dbFactoryGallery.FactoryGalleryID)) { dbItem.FactoryGallery.Remove(dbFactoryGallery); } } foreach (DTO.FactoryGalleryDTO dtoFactoryGallery in dtoItem.FactoryGalleries.ToList()) { FactoryGallery dbFactoryGallery; if (dtoFactoryGallery.FactoryGalleryID <= 0) { dbFactoryGallery = new FactoryGallery(); dbItem.FactoryGallery.Add(dbFactoryGallery); } else { dbFactoryGallery = dbItem.FactoryGallery.FirstOrDefault(o => o.FactoryGalleryID == dtoFactoryGallery.FactoryGalleryID); } if (dbFactoryGallery != null) { AutoMapper.Mapper.Map <DTO.FactoryGalleryDTO, FactoryGallery>(dtoFactoryGallery, dbFactoryGallery); } } } // Factory Document if (dtoItem.factoryDocuments != null) { foreach (FactoryDocument dbFactoryDocument in dbItem.FactoryDocument.ToList()) { if (!dtoItem.factoryDocuments.Select(s => s.FactoryDocmentID).Contains(dbFactoryDocument.FactoryDocmentID)) { dbItem.FactoryDocument.Remove(dbFactoryDocument); } } foreach (DTO.FactoryDocumentDTO dtoFactoryDocument in dtoItem.factoryDocuments.ToList()) { FactoryDocument dbFactoryDocument; if (dtoFactoryDocument.FactoryDocmentID <= 0) { dbFactoryDocument = new FactoryDocument(); dbItem.FactoryDocument.Add(dbFactoryDocument); } else { dbFactoryDocument = dbItem.FactoryDocument.FirstOrDefault(o => o.FactoryDocmentID == dtoFactoryDocument.FactoryDocmentID); } if (dbFactoryDocument != null) { if (dtoFactoryDocument.FactoryDocumentHasChange) { dbFactoryDocument.FactoryDocumentFile = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoFactoryDocument.FactoryDocumentNewFile, dtoFactoryDocument.FactoryDocumentFile, dtoFactoryDocument.FriendlyName); } AutoMapper.Mapper.Map <DTO.FactoryDocumentDTO, FactoryDocument>(dtoFactoryDocument, dbFactoryDocument); } } } // FactoryDirector FactoryContactQuickInfo dbFactoryContactQuickInfo; if (dtoItem.FactoryContactQuickInfos != null) { foreach (var item in dbItem.FactoryContactQuickInfo.ToArray()) { if (!dtoItem.FactoryContactQuickInfos.Select(o => o.FactoryContactQuickInfoID).Contains(item.FactoryContactQuickInfoID)) { dbItem.FactoryContactQuickInfo.Remove(item); } } //map child row foreach (var item in dtoItem.FactoryContactQuickInfos) { if (item.FactoryContactQuickInfoID <= 0) { dbFactoryContactQuickInfo = new FactoryContactQuickInfo(); dbItem.FactoryContactQuickInfo.Add(dbFactoryContactQuickInfo); } else { dbFactoryContactQuickInfo = dbItem.FactoryContactQuickInfo.FirstOrDefault(o => o.FactoryContactQuickInfoID == item.FactoryContactQuickInfoID); } if (dbFactoryContactQuickInfo != null) { AutoMapper.Mapper.Map <DTO.FactoryContactQuickInfo, FactoryContactQuickInfo>(item, dbFactoryContactQuickInfo); } } } // FactoryProductGroup if (dtoItem.FactoryProductGroupDTOs != null) { foreach (var item in dbItem.FactoryProductGroup.ToArray()) { if (!dtoItem.FactoryProductGroupDTOs.Select(o => o.FactoryProductGroupID).Contains(item.FactoryProductGroupID)) { dbItem.FactoryProductGroup.Remove(item); } } //map child row foreach (var item in dtoItem.FactoryProductGroupDTOs) { FactoryProductGroup dbFactoryProductGroup; if (item.FactoryProductGroupID <= 0) { dbFactoryProductGroup = new FactoryProductGroup(); dbItem.FactoryProductGroup.Add(dbFactoryProductGroup); } else { dbFactoryProductGroup = dbItem.FactoryProductGroup.FirstOrDefault(o => o.FactoryProductGroupID == item.FactoryProductGroupID); } if (dbFactoryProductGroup != null) { AutoMapper.Mapper.Map <DTO.FactoryProductGroupDTO, FactoryProductGroup>(item, dbFactoryProductGroup); } } } AutoMapper.Mapper.Map <DTO.Factory, Factory>(dtoItem, dbItem); dbItem.UpdatedDate = dtoItem.UpdatedDate.ConvertStringToDateTime(); }
public void DTO2DB(DTO.FactoryInvoice dtoItem, ref FactoryInvoice dbItem, string _tempFolder) { // map fields AutoMapper.Mapper.Map <DTO.FactoryInvoice, FactoryInvoice>(dtoItem, dbItem); // insert file Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); if (dtoItem.ScanFile_HasChange) { dbItem.ScanFile = fwFactory.CreateNoneImageFilePointer(_tempFolder, dtoItem.ScanFile_NewFile, dtoItem.ScanFile); } if (!string.IsNullOrEmpty(dtoItem.InvoiceDate)) { if (DateTime.TryParse(dtoItem.InvoiceDate, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { dbItem.InvoiceDate = tmpDate; } } decimal subtotal = 0; // map detail if (dtoItem.FactoryInvoiceDetails != null) { // check for child rows deleted foreach (FactoryInvoiceDetail dbDetail in dbItem.FactoryInvoiceDetail.ToArray()) { if (!dtoItem.FactoryInvoiceDetails.Select(o => o.FactoryInvoiceDetailID).Contains(dbDetail.FactoryInvoiceDetailID)) { dbItem.FactoryInvoiceDetail.Remove(dbDetail); } } // map child rows foreach (DTO.FactoryInvoiceDetail dtoDetail in dtoItem.FactoryInvoiceDetails) { FactoryInvoiceDetail dbDetail; if (dtoDetail.FactoryInvoiceDetailID <= 0) { dbDetail = new FactoryInvoiceDetail(); dbItem.FactoryInvoiceDetail.Add(dbDetail); } else { dbDetail = dbItem.FactoryInvoiceDetail.FirstOrDefault(o => o.FactoryInvoiceDetailID == dtoDetail.FactoryInvoiceDetailID); } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.FactoryInvoiceDetail, FactoryInvoiceDetail>(dtoDetail, dbDetail); if (dtoDetail.UnitPrice.HasValue && dtoDetail.Quantity.HasValue) { dbDetail.SubTotal = Math.Round(dtoDetail.UnitPrice.Value * dtoDetail.Quantity.Value, 2, MidpointRounding.AwayFromZero); subtotal += Math.Round(dtoDetail.UnitPrice.Value * dtoDetail.Quantity.Value, 2, MidpointRounding.AwayFromZero); } } } } // map sparepart detail if (dtoItem.FactoryInvoiceSparepartDetails != null) { // check for child rows deleted foreach (FactoryInvoiceSparepartDetail dbSparepartDetail in dbItem.FactoryInvoiceSparepartDetail.ToArray()) { if (!dtoItem.FactoryInvoiceSparepartDetails.Select(o => o.FactoryInvoiceSparepartDetailID).Contains(dbSparepartDetail.FactoryInvoiceSparepartDetailID)) { dbItem.FactoryInvoiceSparepartDetail.Remove(dbSparepartDetail); } } // map child rows foreach (DTO.FactoryInvoiceSparepartDetail dtoSparepartDetail in dtoItem.FactoryInvoiceSparepartDetails) { FactoryInvoiceSparepartDetail dbSparepartDetail; if (dtoSparepartDetail.FactoryInvoiceSparepartDetailID <= 0) { dbSparepartDetail = new FactoryInvoiceSparepartDetail(); dbItem.FactoryInvoiceSparepartDetail.Add(dbSparepartDetail); } else { dbSparepartDetail = dbItem.FactoryInvoiceSparepartDetail.FirstOrDefault(o => o.FactoryInvoiceSparepartDetailID == dtoSparepartDetail.FactoryInvoiceSparepartDetailID); } if (dbSparepartDetail != null) { AutoMapper.Mapper.Map <DTO.FactoryInvoiceSparepartDetail, FactoryInvoiceSparepartDetail>(dtoSparepartDetail, dbSparepartDetail); if (dtoSparepartDetail.UnitPrice.HasValue && dtoSparepartDetail.Quantity.HasValue) { dbSparepartDetail.SubTotal = Math.Round(dtoSparepartDetail.UnitPrice.Value * dtoSparepartDetail.Quantity.Value, 2, MidpointRounding.AwayFromZero); subtotal += Math.Round(dtoSparepartDetail.UnitPrice.Value * dtoSparepartDetail.Quantity.Value, 2, MidpointRounding.AwayFromZero); } } } } // map extra if (dtoItem.FactoryInvoiceExtras != null) { // check for child rows deleted foreach (FactoryInvoiceExtra dbExtra in dbItem.FactoryInvoiceExtra.ToArray()) { if (!dtoItem.FactoryInvoiceExtras.Select(o => o.FactoryInvoiceExtraID).Contains(dbExtra.FactoryInvoiceExtraID)) { dbItem.FactoryInvoiceExtra.Remove(dbExtra); } } // map child rows foreach (DTO.FactoryInvoiceExtra dtoExtra in dtoItem.FactoryInvoiceExtras) { FactoryInvoiceExtra dbExtra; if (dtoExtra.FactoryInvoiceExtraID <= 0) { dbExtra = new FactoryInvoiceExtra(); dbItem.FactoryInvoiceExtra.Add(dbExtra); } else { dbExtra = dbItem.FactoryInvoiceExtra.FirstOrDefault(o => o.FactoryInvoiceExtraID == dtoExtra.FactoryInvoiceExtraID); } if (dbExtra != null) { AutoMapper.Mapper.Map <DTO.FactoryInvoiceExtra, FactoryInvoiceExtra>(dtoExtra, dbExtra); if (dtoExtra.UnitPrice.HasValue && dtoExtra.Quantity.HasValue) { dbExtra.SubTotal = Math.Round(dtoExtra.UnitPrice.Value * dtoExtra.Quantity.Value, 2, MidpointRounding.AwayFromZero); subtotal += Math.Round(dtoExtra.UnitPrice.Value * dtoExtra.Quantity.Value, 2, MidpointRounding.AwayFromZero); } } } } dbItem.SubTotalAmount = subtotal; if (dbItem.DeductedAmount.HasValue) { dbItem.TotalAmount = dbItem.SubTotalAmount.Value - dbItem.DeductedAmount.Value; } else { dbItem.TotalAmount = dbItem.SubTotalAmount; } }
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 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 bool UpdateData(int id, ref DTO.MaterialTypeMng.MaterialType dtoItem, int userId, out Library.DTO.Notification notification) { notification = new Notification(); notification.Type = NotificationType.Success; int number; string indexName; try { using (var context = CreateContext()) { MaterialType materialType = null; if (id == 0) { materialType = new MaterialType(); context.MaterialType.Add(materialType); } else { materialType = context.MaterialType.FirstOrDefault(o => o.MaterialTypeID == id); } if (materialType == null) { notification.Message = "Material Type not found!"; return(false); } else { //hangtag image Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); // Fixed bug check dtoItem.HangTagFileHasChange has value after get value - 21 FEB 2018. if (dtoItem.HangTagFileHasChange.HasValue) { dtoItem.HangTagFile = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoItem.NewHangTagFile, dtoItem.HangTagFile); } converter.DTO2BD_MaterialType(dtoItem, ref materialType); if (id <= 0) { // Generate code. using (var trans = context.Database.BeginTransaction()) { context.Database.ExecuteSqlCommand("SELECT * FROM MaterialType WITH (TABLOCKX, HOLDLOCK)"); try { var newCode = context.MaterialTypeMng_function_GenerateCode().FirstOrDefault(); if (!"**".Equals(newCode)) { materialType.MaterialTypeUD = 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.SaveChanges(); } dtoItem = GetData(materialType.MaterialTypeID, 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 ("MaterialTypeUDUnique".Equals(indexName)) { notification.Message = "The Material Type Code is already exists."; } } else { notification.Message = exData.Message; } return(false); } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = ex.Message; return(false); } }
public override bool UpdateData(int id, ref DTO.ImageGalleryMng.ImageGallery dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (ImageGalleryMngEntities context = CreateContext()) { ImageGallery dbItem = null; if (id == 0) { dbItem = new ImageGallery(); context.ImageGallery.Add(dbItem); } else { dbItem = context.ImageGallery.FirstOrDefault(o => o.ImageGalleryID == id); } if (dbItem == null) { notification.Message = "Item 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); } // process image foreach (DTO.ImageGalleryMng.ImageGalleryVersion dtoVersion in dtoItem.ImageGalleryVersions.Where(o => o.HasChange)) { //dbItem.FileUD = (new Framework.DataFactory()).CreateFilePointer(this._TempFolder, dtoItem.NewFile, dtoItem.FileUD); string[] videoExtension = { "avi", "mp4", "wmv", "flv" }; if (videoExtension.Contains(dtoVersion.NewFile.Substring(dtoVersion.NewFile.Length - 3, 3).ToLower())) { dtoVersion.FileUD = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoVersion.NewFile, dtoVersion.FileUD); } else { dtoVersion.FileUD = fwFactory.CreateFilePointer(this._TempFolder, dtoVersion.NewFile, dtoVersion.FileUD); } } converter.DTO2DB(dtoItem, ref dbItem); // remove orphan context.ImageGalleryClient.Local.Where(o => o.ImageGallery == null).ToList().ForEach(o => context.ImageGalleryClient.Remove(o)); foreach (ImageGalleryVersion dbVersion in context.ImageGalleryVersion.Local.Where(o => o.ImageGallery == null).ToList()) { // remove images if (!string.IsNullOrEmpty(dbVersion.FileUD)) { fwFactory.RemoveImageFile(dbVersion.FileUD); } } context.ImageGalleryVersion.Local.Where(o => o.ImageGallery == null).ToList().ForEach(o => context.ImageGalleryVersion.Remove(o)); context.SaveChanges(); dtoItem = GetData(dbItem.ImageGalleryID, out notification).Data; return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { ComplianceProcessDTO inputParam = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <ComplianceProcessDTO>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); try { using (ComplianceMngEntities context = CreateContext()) { ComplianceProcess dbItem = null; if (id == 0) { dbItem = new ComplianceProcess(); context.ComplianceProcess.Add(dbItem); dbItem.ComplianceProcessUD = context.ComplianceMng_function_GenerateCode().FirstOrDefault(); } else { //get db item dbItem = context.ComplianceProcess.FirstOrDefault(o => o.ComplianceProcessID == id); } if (dbItem == null) { notification.Message = "Comliance not found!"; return(false); } else { dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; // process Detail foreach (DTO.ComplianceAttachedFileDTO dtoDetail in inputParam.ComplianceAttachedFileDTOs) { // FileUD if (dtoDetail.FileUDHasChange) { if (string.IsNullOrEmpty(dtoDetail.NewFileUD)) { if (dtoDetail.FileUD == dtoDetail.NewFileUD) { dtoDetail.FileUD = null; } else { fwFactory.RemoveFile(dtoDetail.FileUD); } } else { dtoDetail.FileUD = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoDetail.NewFileUD, dtoDetail.FileUD, dtoDetail.FileUDFriendlyName); } } } foreach (DTO.CompliancePICDTO dtoDetail in inputParam.CompliancePICDTOs) { // FileUD if (dtoDetail.FileUDHasChange) { if (string.IsNullOrEmpty(dtoDetail.NewFileUD)) { if (dtoDetail.FileUD == dtoDetail.NewFileUD) { dtoDetail.FileUD = null; } else { fwFactory.RemoveFile(dtoDetail.FileUD); } } else { dtoDetail.FileUD = fwFactory.CreateNoneImageFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoDetail.NewFileUD, dtoDetail.FileUD, dtoDetail.FileUDFriendlyName); } } } //read dto to db converter.DTO2DB_ComplianceProcess(inputParam, ref dbItem, userId); //delete offerline is null context.ComplianceAttachedFile.Local.Where(o => o.ComplianceProcess == null).ToList().ForEach(o => context.ComplianceAttachedFile.Remove(o)); context.CompliancePIC.Local.Where(o => o.ComplianceProcess == null).ToList().ForEach(o => context.CompliancePIC.Remove(o)); //save data context.SaveChanges(); //reload data if (id > 0) { dtoItem = new ComplianceProcessDTO { ComplianceProcessID = id }; } else { dtoItem = new ComplianceProcessDTO { ComplianceProcessID = dbItem.ComplianceProcessID }; } return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.HandleExceptionSingleLine(ex); } return(false); }
public void DTO2BD(DTO.CushionColorMng.CushionColor dtoItem, string tempFolder, ref CushionColor dbItem) { AutoMapper.Mapper.Map <DTO.CushionColorMng.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.CushionColorMng.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.CushionColorMng.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); } } Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); // Mapping cushion color test report rows foreach (DTO.CushionColorMng.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.CushionColorMng.CushionColorTestReport, CushionColorTestReport>(dtoCushionColorTestReport, dbCushionColorTestReport); if (dtoCushionColorTestReport.File_HasChange.HasValue && dtoCushionColorTestReport.File_HasChange.Value) { dbCushionColorTestReport.FileUD = fwFactory.CreateNoneImageFilePointer(tempFolder, dtoCushionColorTestReport.File_NewFile, dtoCushionColorTestReport.FileUD); } } } } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.AVFPurchasingInvoice dtoAVFPurchasingInvoice = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.AVFPurchasingInvoice>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (AVFPurchasingInvoiceMngEntities context = CreateContext()) { AVFPurchasingInvoice dbItem = null; if (id == 0) { dbItem = new AVFPurchasingInvoice(); context.AVFPurchasingInvoice.Add(dbItem); } else { dbItem = context.AVFPurchasingInvoice.FirstOrDefault(o => o.AVFPurchasingInvoiceID == id); } if (dbItem == null) { notification.Message = "Invoice not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoAVFPurchasingInvoice.ConcurrencyFlag_String))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } //convert dto to db converter.DTO2BD(dtoAVFPurchasingInvoice, ref dbItem); //remove orphan item context.AVFPurchasingInvoiceDetail.Local.Where(o => o.AVFPurchasingInvoice == null).ToList().ForEach(o => context.AVFPurchasingInvoiceDetail.Remove(o)); // processing file if (dtoAVFPurchasingInvoice.PDFFileScan_HasChange) { dbItem.PDFFileScan = fwFactory.CreateNoneImageFilePointer(this._tempFolder, dtoAVFPurchasingInvoice.PDFFileScan_NewFile, dtoAVFPurchasingInvoice.PDFFileScan); } dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = userId; context.SaveChanges(); dtoItem = GetData(dbItem.AVFPurchasingInvoiceID, 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 id, ref DTO.MaterialOptionMng.MaterialOption dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; int number; string indexName; try { using (MaterialOptionMngEntities context = CreateContext()) { MaterialOption dbItem = null; if (id == 0) { dbItem = new MaterialOption(); context.MaterialOption.Add(dbItem); dbItem.CreatedBy = dtoItem.UpdatedBy; dbItem.CreatedDate = DateTime.Now; } else { dbItem = context.MaterialOption.FirstOrDefault(o => o.MaterialOptionID == id); dbItem.UpdatedBy = dtoItem.UpdatedBy; dbItem.UpdatedDate = DateTime.Now; } if (dbItem == null) { notification.Message = "Material 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); } // process test report foreach (var dtoReport in dtoItem.MaterialOptionTestReports.Where(o => o.TestReportHasChange)) { dtoReport.FileUD = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoReport.TestReportNewFile, dtoReport.FileUD); } // save data converter.DTO2DB(dtoItem, ref dbItem); context.MaterialOptionTestReport.Local.Where(o => o.MaterialOption == null).ToList().ForEach(o => context.MaterialOptionTestReport.Remove(o)); // processing image if (dtoItem.ImageFile_HasChange) { dbItem.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.ImageFile_NewFile, dtoItem.ImageFile); } context.SaveChanges(); // Handle notification missing information. string emailSubject = (id == 0) ? "TASK REQUEST [CREATE MATERIAL OPTION]" : "TASK REQUEST [UPDATE MATERIAL OPTION]"; string emailBody = string.Empty; if (!IsNullPropertiesMaterialOption(dbItem, ref emailBody)) { SendToEmailNotification(context, emailSubject, emailBody); } dtoItem = GetData(dbItem.MaterialOptionID, out notification).Data; return(true); } } } catch (System.Data.DataException dEx) { notification.Type = Library.DTO.NotificationType.Error; Library.ErrorHelper.DataExceptionParser(dEx, out number, out indexName); if (number == 2601 && !string.IsNullOrEmpty(indexName)) { if (indexName == "MaterialTypeColorUnique") { notification.Message = "The combination of Material, Material Type and Material Color is already exists"; } } else { notification.Message = dEx.Message; } return(false); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }