private string CreateImge(string byteString, string imgStr) { if (byteString == null || byteString.Equals("")) { return(string.Empty); } if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Media/Temp/" + "/android/"))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Media/Temp/" + "/android/")); } var uploadPath = HttpContext.Current.Server.MapPath("~/Media/Temp/" + "/android/"); string fileName = imgStr + ".jpeg"; if (getExistsFile(fileName) == false) { using (var fs = new FileStream(Path.Combine(uploadPath, fileName), FileMode.Create)) { byte[] buffer = System.Convert.FromBase64String(byteString); fs.Write(buffer, 0, buffer.Length); } return(fwFactory.CreateFilePointer(uploadPath, fileName, null)); } else { return(getFileUD(fileName)); } }
public bool UpdateUserProfile(int userId, ref DTO.ProfileMng.User dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (ProfileMngEntities context = CreateContext()) { UserProfile dbItem = context.UserProfile.FirstOrDefault(o => o.UserId == userId); if (dbItem == null) { notification.Message = "User 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.DTO2DB(dtoItem, ref dbItem); context.SaveChanges(); // processing image if (dtoItem.PersonalPhoto_HasChange) { dbItem.PersonalPhoto = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.PersonalPhoto_NewFile, dtoItem.PersonalPhoto); } if (dtoItem.SignatureImage_HasChange) { dbItem.SignatureImage = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.SignatureImage_NewFile, dtoItem.SignatureImage); } context.SaveChanges(); dtoItem = GetUserProfile(userId, out notification); return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }
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 override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.TransportOfferDTO dtoTransportOffer = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.TransportOfferDTO>(); try { using (TransportOfferEntities context = CreateContext()) { TransportOffer dbItem = null; if (id > 0) { dbItem = context.TransportOffer.Where(o => o.TransportOfferID == id).FirstOrDefault(); } else { dbItem = new TransportOffer(); context.TransportOffer.Add(dbItem); } if (dbItem == null) { notification.Message = "data not found!"; return(false); } else { Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; if (dtoTransportOffer.File_HasChange.HasValue && dtoTransportOffer.File_HasChange.Value) { dtoTransportOffer.FileUD = fwFactory.CreateFilePointer(tempFolder, dtoTransportOffer.File_NewFile, dtoTransportOffer.FileUD, dtoTransportOffer.FriendlyName); } //convert dto to db converter.DTO2DB_TransportOffer(dtoTransportOffer, ref dbItem); dbItem.UpdatedBy = userId; //remove orphan context.TransportOfferCostDetail.Local.Where(o => o.TransportOffer == null).ToList().ForEach(o => context.TransportOfferCostDetail.Remove(o)); context.TransportOfferConditionDetail.Local.Where(o => o.TransportOffer == null).ToList().ForEach(o => context.TransportOfferConditionDetail.Remove(o)); //save data context.SaveChanges(); //get return data dtoItem = GetData(userId, dbItem.TransportOfferID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; notification.DetailMessage.Add(ex.Message); if (ex.GetBaseException() != null) { notification.DetailMessage.Add(ex.GetBaseException().Message); } return(false); } }
private void cmdImport_tabTILSOFTFile_Click(object sender, EventArgs e) { string uniqueFileName = Path.GetTempPath() + @"\" + System.Guid.NewGuid().ToString().Replace("-", "") + ".xlsx"; string pointer = string.Empty; System.IO.FileInfo epFInfo = new System.IO.FileInfo(uniqueFileName); OfficeOpenXml.ExcelPackage ePackagae = new OfficeOpenXml.ExcelPackage(epFInfo); OfficeOpenXml.ExcelWorksheet pWS = ePackagae.Workbook.Worksheets.Add("Result"); List <DTO.FilePointer> result = new List <DTO.FilePointer>(); foreach (FileInfo fInfo in (new DirectoryInfo(FrameworkSetting.Setting.AbsoluteReportTmpFolder)).GetFiles()) { pointer = string.Empty; DTO.FilePointer fPointer = new DTO.FilePointer() { PhysicalFileName = fInfo.Name }; try { fPointer.FilePointerUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteReportTmpFolder, fInfo.Name, string.Empty); fwFactory.CreateImageCache(fPointer.FilePointerUD, 120, 120, false); result.Add(fPointer); } catch (Exception ex) { } } pWS.Cells["A1"].LoadFromCollection(result, true); ePackagae.Save(); System.Diagnostics.Process.Start(uniqueFileName); }
public void DTO2DB_TaskStepComment(DTO.TaskStepComment dtoItem, ref TaskStepComment dbItem, string _tempFolder) { // map fields AutoMapper.Mapper.Map <DTO.TaskStepComment, TaskStepComment>(dtoItem, dbItem); // map file if (dtoItem.TaskStepCommentFiles != null) { // check for child rows deleted foreach (TaskStepCommentFile dbFile in dbItem.TaskStepCommentFile.ToArray()) { if (!dtoItem.TaskStepCommentFiles.Select(o => o.TaskStepCommentFileID).Contains(dbFile.TaskStepCommentFileID)) { if (!string.IsNullOrEmpty(dbFile.FileUD)) { fwFactory.RemoveFile(dbFile.FileUD); } dbItem.TaskStepCommentFile.Remove(dbFile); } } // map child rows foreach (DTO.TaskStepCommentFile dtoFile in dtoItem.TaskStepCommentFiles) { TaskStepCommentFile dbFile; if (dtoFile.TaskStepCommentFileID <= 0) { dbFile = new TaskStepCommentFile(); dbItem.TaskStepCommentFile.Add(dbFile); } else { dbFile = dbItem.TaskStepCommentFile.FirstOrDefault(o => o.TaskStepCommentFileID == dtoFile.TaskStepCommentFileID); } if (dbFile != null) { if (dtoFile.HasChanged) { dbFile.FileUD = fwFactory.CreateFilePointer(_tempFolder, dtoFile.NewFile, dtoFile.FileUD, dtoFile.FriendlyName); } AutoMapper.Mapper.Map <DTO.TaskStepCommentFile, TaskStepCommentFile>(dtoFile, dbFile); } } } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification) { DTO.FrameMaterialProfile dtoFrameMaterialProfile = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FrameMaterialProfile>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (FrameMaterialProfileMngEntities context = CreateContext()) { FrameMaterialProfile dbItem = null; if (id == 0) { dbItem = new FrameMaterialProfile(); context.FrameMaterialProfile.Add(dbItem); } else { dbItem = context.FrameMaterialProfile.FirstOrDefault(o => o.FrameMaterialProfileID == id); } if (dbItem == null) { notification.Message = "Profile not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoFrameMaterialProfile.ConcurrencyFlag_String))) { throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT); } converter.DTO2BD(dtoFrameMaterialProfile, ref dbItem); context.SaveChanges(); // processing image if (dtoFrameMaterialProfile.ImageFile_HasChange) { dbItem.ImageFile = fwFactory.CreateFilePointer(this._tempFolder, dtoFrameMaterialProfile.ImageFile_NewFile, dtoFrameMaterialProfile.ImageFile); } context.SaveChanges(); dtoItem = GetData(dbItem.FrameMaterialProfileID, 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.CushionMng.Cushion dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (CushionMngEntities context = CreateContext()) { Cushion dbItem = null; if (id == 0) { dbItem = new Cushion(); context.Cushion.Add(dbItem); } else { dbItem = context.Cushion.FirstOrDefault(o => o.CushionID == id); } if (dbItem == null) { notification.Message = "Cushion 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); } context.SaveChanges(); dtoItem = GetData(dbItem.CushionID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public void DTO2DB_ProductInfo(DTO.ProductInfo.ProductDTO dtoItem, ref SampleProduct dbItem, string TmpFile) { AutoMapper.Mapper.Map <DTO.ProductInfo.ProductDTO, SampleProduct>(dtoItem, dbItem); // remark image foreach (SampleReferenceImage dbImage in dbItem.SampleReferenceImage.ToArray()) { if (!dtoItem.ReferenceImageDTOs.Select(o => o.SampleReferenceImageID).Contains(dbImage.SampleReferenceImageID)) { // delete files if (!string.IsNullOrEmpty(dbImage.FileUD)) { fwFactory.RemoveImageFile(dbImage.FileUD); } dbItem.SampleReferenceImage.Remove(dbImage); } } foreach (DTO.ProductInfo.ReferenceImageDTO dtoImage in dtoItem.ReferenceImageDTOs) { SampleReferenceImage dbImage; if (dtoImage.SampleReferenceImageID <= 0) { dbImage = new SampleReferenceImage(); dbItem.SampleReferenceImage.Add(dbImage); } else { dbImage = dbItem.SampleReferenceImage.FirstOrDefault(o => o.SampleReferenceImageID == dtoImage.SampleReferenceImageID); } if (dbItem != null) { AutoMapper.Mapper.Map <DTO.ProductInfo.ReferenceImageDTO, SampleReferenceImage>(dtoImage, dbImage); if (!string.IsNullOrEmpty(dtoImage.BringInDate)) { if (DateTime.TryParse(dtoImage.BringInDate, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { dbImage.BringInDate = tmpDate; } } if (dtoImage.HasChanged && !string.IsNullOrEmpty(dtoImage.NewFile)) { dbImage.FileUD = fwFactory.CreateFilePointer(TmpFile, dtoImage.NewFile, dbImage.FileUD); } } } }
public void DTO2DB_ShowroomItem(DTO.ShowroomItemMng.ShowroomItem dtoItem, ref ShowroomItem dbItem, string tempFolder) { if (dtoItem.ImageFile_HasChange.HasValue && dtoItem.ImageFile_HasChange.Value) { dtoItem.ImageFile = fwFactory.CreateFilePointer(tempFolder, dtoItem.ImageFile_NewFile, dtoItem.ImageFile); } AutoMapper.Mapper.Map <DTO.ShowroomItemMng.ShowroomItem, ShowroomItem>(dtoItem, dbItem); if (dtoItem.ShowroomItemID > 0) { dbItem.UpdatedDate = DateTime.Now; dbItem.UpdatedBy = dtoItem.UpdatedBy; } else { dbItem.CreatedDate = DateTime.Now; dbItem.CreatedBy = dtoItem.UpdatedBy; } }
public void DTO2DB_FactoryMaterial(DTO.FactoryMaterial dtoItem, ref FactoryMaterial dbItem, string tempFolder) { Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); if (dtoItem.FactoryMaterialImages != null) { foreach (var item in dbItem.FactoryMaterialImage.ToArray()) { if (!dtoItem.FactoryMaterialImages.Select(s => s.FactoryMaterialImageID).Contains(item.FactoryMaterialImageID)) { dbItem.FactoryMaterialImage.Remove(item); } } foreach (var item in dtoItem.FactoryMaterialImages) { //modify dto image field if (item.ImageFile_HasChange.HasValue && item.ImageFile_HasChange.Value) { item.ImageFile = fwFactory.CreateFilePointer(tempFolder, item.ImageFile_NewFile, item.ImageFile); } //read db image field FactoryMaterialImage dbDetail; if (item.FactoryMaterialImageID < 0) { dbDetail = new FactoryMaterialImage(); dbItem.FactoryMaterialImage.Add(dbDetail); } else { dbDetail = dbItem.FactoryMaterialImage.Where(o => o.FactoryMaterialImageID == item.FactoryMaterialImageID).FirstOrDefault(); } //map from dto image field to db image field if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.FactoryMaterialImage, FactoryMaterialImage>(item, dbDetail); } } } AutoMapper.Mapper.Map <DTO.FactoryMaterial, FactoryMaterial>(dtoItem, dbItem); }
public void DTO2DB_ShowroomArea(DTO.ShowroomAreaMng.ShowroomArea dtoItem, ref ShowroomArea dbItem, string tempFolder) { List <ShowroomAreaImage> image_tobedeleted = new List <ShowroomAreaImage>(); if (dtoItem.ShowroomAreaImages != null) { //CHECK foreach (var dbDetail in dbItem.ShowroomAreaImage.Where(o => !dtoItem.ShowroomAreaImages.Select(s => s.ShowroomAreaImageID).Contains(o.ShowroomAreaImageID))) { image_tobedeleted.Add(dbDetail); } foreach (var dbDetail in image_tobedeleted) { dbItem.ShowroomAreaImage.Remove(dbDetail); } //MAP foreach (var item in dtoItem.ShowroomAreaImages) { if (item.ImageFile_HasChange.HasValue && item.ImageFile_HasChange.Value) { item.ImageFile = fwFactory.CreateFilePointer(tempFolder, item.ImageFile_NewFile, item.ImageFile); } ShowroomAreaImage dbAreaImage; if (item.ShowroomAreaImageID < 0) { dbAreaImage = new ShowroomAreaImage(); dbItem.ShowroomAreaImage.Add(dbAreaImage); } else { dbAreaImage = dbItem.ShowroomAreaImage.FirstOrDefault(o => o.ShowroomAreaImageID == item.ShowroomAreaImageID); } if (dbAreaImage != null) { AutoMapper.Mapper.Map <DTO.ShowroomAreaMng.ShowroomAreaImage, ShowroomAreaImage>(item, dbAreaImage); } } } AutoMapper.Mapper.Map <DTO.ShowroomAreaMng.ShowroomArea, ShowroomArea>(dtoItem, dbItem); }
public void DTO2DB_SampleProgress(DTO.SampleProgressDTO dtoItem, ref SampleProgress dbItem, string TmpFile, int userId) { // progress AutoMapper.Mapper.Map <DTO.SampleProgressDTO, SampleProgress>(dtoItem, dbItem); // progress image foreach (SampleProgressImage dbImage in dbItem.SampleProgressImage.ToArray()) { if (!dtoItem.SampleProgressImageDTOs.Select(o => o.SampleProgressImageID).Contains(dbImage.SampleProgressImageID)) { if (!string.IsNullOrEmpty(dbImage.FileUD)) { // remove image file fwFactory.RemoveImageFile(dbImage.FileUD); } dbItem.SampleProgressImage.Remove(dbImage); } } foreach (DTO.SampleProgressImageDTO dtoImage in dtoItem.SampleProgressImageDTOs) { SampleProgressImage dbImage; if (dtoImage.SampleProgressImageID <= 0) { dbImage = new SampleProgressImage(); dbItem.SampleProgressImage.Add(dbImage); } else { dbImage = dbItem.SampleProgressImage.FirstOrDefault(o => o.SampleProgressImageID == dtoImage.SampleProgressImageID); } if (dbImage != null) { // change or add images if (dtoImage.HasChanged) { dbImage.FileUD = fwFactory.CreateFilePointer(TmpFile, dtoImage.NewFile, dtoImage.FileUD); } AutoMapper.Mapper.Map <DTO.SampleProgressImageDTO, SampleProgressImage>(dtoImage, dbImage); } } }
public void DTO2DB(DTO.NhanVienDTO dtoItem, ref NhanVien dbItem, int userId) { string TmpFile = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; // remark if (dtoItem.PhotoHasChanged) { dtoItem.Photo = fwFactory.CreateFilePointer(TmpFile, dtoItem.NewPhoto, dtoItem.Photo); } AutoMapper.Mapper.Map <DTO.NhanVienDTO, NhanVien>(dtoItem, dbItem); // remark image foreach (NguoiPhuThuoc dbNPT in dbItem.NguoiPhuThuoc.ToArray()) { if (!dtoItem.NguoiPhuThuocDTOs.Select(o => o.NguoiPhuThuocID).Contains(dbNPT.NguoiPhuThuocID)) { dbItem.NguoiPhuThuoc.Remove(dbNPT); } } foreach (DTO.NguoiPhuThuocDTO dtoNPT in dtoItem.NguoiPhuThuocDTOs) { NguoiPhuThuoc dbNPT; if (dtoNPT.NguoiPhuThuocID <= 0) { dbNPT = new NguoiPhuThuoc(); dbItem.NguoiPhuThuoc.Add(dbNPT); } else { dbNPT = dbItem.NguoiPhuThuoc.FirstOrDefault(o => o.NguoiPhuThuocID == dtoNPT.NguoiPhuThuocID); } if (dbNPT != null) { AutoMapper.Mapper.Map <DTO.NguoiPhuThuocDTO, NguoiPhuThuoc>(dtoNPT, dbNPT); } } }
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.LoadingPlan dtoItem, ref LoadingPlan dbItem, string _tempFolder, bool mapDetail) { // map fields AutoMapper.Mapper.Map <DTO.LoadingPlan, LoadingPlan>(dtoItem, dbItem); // insert image Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); if (dtoItem.ProductPicture1_HasChange) { dbItem.ProductPicture1 = fwFactory.CreateFilePointer(_tempFolder, dtoItem.ProductPicture1_NewFile, dtoItem.ProductPicture1); } if (dtoItem.ProductPicture2_HasChange) { dbItem.ProductPicture2 = fwFactory.CreateFilePointer(_tempFolder, dtoItem.ProductPicture2_NewFile, dtoItem.ProductPicture2); } if (dtoItem.ContainerPicture1_HasChange) { dbItem.ContainerPicture1 = fwFactory.CreateFilePointer(_tempFolder, dtoItem.ContainerPicture1_NewFile, dtoItem.ContainerPicture1); } if (dtoItem.ContainerPicture2_HasChange) { dbItem.ContainerPicture2 = fwFactory.CreateFilePointer(_tempFolder, dtoItem.ContainerPicture2_NewFile, dtoItem.ContainerPicture2); } if (!string.IsNullOrEmpty(dtoItem.ShipmentDate)) { if (DateTime.TryParse(dtoItem.ShipmentDate, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { dbItem.ShipmentDate = tmpDate; } } if (!string.IsNullOrEmpty(dtoItem.LoadingDate)) { if (DateTime.TryParse(dtoItem.LoadingDate, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { dbItem.LoadingDate = tmpDate; } } if (mapDetail) { // map detail if (dtoItem.LoadingPlanDetails != null) { // check for child rows deleted foreach (LoadingPlanDetail dbDetail in dbItem.LoadingPlanDetail.ToArray()) { if (!dtoItem.LoadingPlanDetails.Select(o => o.LoadingPlanDetailID).Contains(dbDetail.LoadingPlanDetailID)) { dbItem.LoadingPlanDetail.Remove(dbDetail); } } // map child rows foreach (DTO.LoadingPlanDetail dtoDetail in dtoItem.LoadingPlanDetails) { LoadingPlanDetail dbDetail; if (dtoDetail.LoadingPlanDetailID <= 0) { dbDetail = new LoadingPlanDetail(); dbItem.LoadingPlanDetail.Add(dbDetail); } else { dbDetail = dbItem.LoadingPlanDetail.FirstOrDefault(o => o.LoadingPlanDetailID == dtoDetail.LoadingPlanDetailID); } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.LoadingPlanDetail, LoadingPlanDetail>(dtoDetail, dbDetail); } } } // map sparepart detail if (dtoItem.LoadingPlanSparepartDetails != null) { // check for child rows deleted foreach (LoadingPlanSparepartDetail dbSparepartDetail in dbItem.LoadingPlanSparepartDetail.ToArray()) { if (!dtoItem.LoadingPlanSparepartDetails.Select(o => o.LoadingPlanSparepartDetailID).Contains(dbSparepartDetail.LoadingPlanSparepartDetailID)) { dbItem.LoadingPlanSparepartDetail.Remove(dbSparepartDetail); } } // map child rows foreach (DTO.LoadingPlanSparepartDetail dtoSparepartDetail in dtoItem.LoadingPlanSparepartDetails) { LoadingPlanSparepartDetail dbSparepartDetail; if (dtoSparepartDetail.LoadingPlanSparepartDetailID <= 0) { dbSparepartDetail = new LoadingPlanSparepartDetail(); dbItem.LoadingPlanSparepartDetail.Add(dbSparepartDetail); } else { dbSparepartDetail = dbItem.LoadingPlanSparepartDetail.FirstOrDefault(o => o.LoadingPlanSparepartDetailID == dtoSparepartDetail.LoadingPlanSparepartDetailID); } if (dbSparepartDetail != null) { AutoMapper.Mapper.Map <DTO.LoadingPlanSparepartDetail, LoadingPlanSparepartDetail>(dtoSparepartDetail, dbSparepartDetail); } } } } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.PurchaseOrderDto dtoPurchaseOrder = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.PurchaseOrderDto>(); try { //get companyID Module.Framework.DAL.DataFactory fw_factory = new Framework.DAL.DataFactory(); int?companyID = fw_factory.GetCompanyID(userId); using (PurchaseOrderMngEntities context = CreateContext()) { PurchaseOrder dbItem = null; if (id == 0) { dbItem = new PurchaseOrder(); context.PurchaseOrder.Add(dbItem); } else { dbItem = context.PurchaseOrder.Where(o => o.PurchaseOrderID == id).FirstOrDefault(); } if (dbItem == null) { notification.Message = "data not found!"; return(false); } else { //upload file Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; if (dtoPurchaseOrder.File_HasChange.HasValue && dtoPurchaseOrder.File_HasChange.Value) { dtoPurchaseOrder.AttachedFile = fwFactory.CreateFilePointer(tempFolder, dtoPurchaseOrder.File_NewFile, dtoPurchaseOrder.AttachedFile, dtoPurchaseOrder.FriendlyName); } // //convert dto to db converter.DTO2DB_PurchaseOrder(dtoPurchaseOrder, ref dbItem); dbItem.CompanyID = companyID; dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; if (id == 0) { //dbItem.PurchaseOrderUD = context.PurchaseOrderMng_function_GeneratePurchaseOrderUD(dtoPurchaseOrder.FactoryRawMaterialUD, dtoPurchaseOrder.PurchaseOrderDate, dtoPurchaseOrder.FactoryRawMaterialID).FirstOrDefault(); dbItem.CreatedBy = userId; dbItem.CreatedDate = DateTime.Now; if (dtoPurchaseOrder.PurchaseOrderStatusID != 4) { dbItem.PurchaseOrderStatusID = 1; } } // loop dto item detail foreach (var item in dtoPurchaseOrder.PurchaseOrderDetailDTOs) { if (item.IsChangePrice == true) { PurchaseOrderDetailPriceHistory dbItemPriceHistory = new PurchaseOrderDetailPriceHistory(); context.PurchaseOrderDetailPriceHistory.Add(dbItemPriceHistory); dbItemPriceHistory.PurchaseOrderDetailID = (int)item.PurchaseOrderDetailID; dbItemPriceHistory.UnitPrice = (decimal)item.UnitPrice; dbItemPriceHistory.ApprovedBy = userId; dbItemPriceHistory.ApprovedDate = DateTime.Now; } } //remove orphan context.PurchaseOrderDetail.Local.Where(o => o.PurchaseOrder == null).ToList().ForEach(o => context.PurchaseOrderDetail.Remove(o)); context.PurchaseOrderWorkOrderDetail.Local.Where(o => o.PurchaseOrderDetail == null).ToList().ForEach(o => context.PurchaseOrderWorkOrderDetail.Remove(o)); context.PurchaseOrderDetailReceivingPlan.Local.Where(o => o.PurchaseOrderDetail == null).ToList().ForEach(o => context.PurchaseOrderDetailReceivingPlan.Remove(o)); context.PurchaseOrderDetailPriceHistory.Local.Where(o => o.PurchaseOrderDetail == null).ToList().ForEach(o => context.PurchaseOrderDetailPriceHistory.Remove(o)); //save data context.SaveChanges(); // Generate PurchaseOrderUD. if (id == 0) { context.PurchaseOrderMng_function_GeneratePurchaseOrderUD(dbItem.Season, dbItem.FactoryRawMaterialID, dbItem.PurchaseOrderID); } else { // Auto update unit price in receiving note UpdateUnitPriceReceivingNoteDetail(dbItem.PurchaseOrderID, out notification); } //get return data dtoItem = GetData(userId, dbItem.PurchaseOrderID, out notification).Data; if (id == 0) { string emailSubject = string.Format("[Tilsoft] - Purchasing Order - {0} - {1}", dbItem.PurchaseOrderUD, dtoPurchaseOrder.FactoryRawMaterialShortNM); string emailBody = string.Format("Please approve PO: {0} - {1} - {2}", dbItem.PurchaseOrderUD, dtoPurchaseOrder.FactoryRawMaterialShortNM, "http://app.tilsoft.bg/PurchaseOrderMng/Edit/" + dbItem.PurchaseOrderID); SendNotification(emailSubject, emailBody); } return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; notification.DetailMessage.Add(ex.Message); if (ex.GetBaseException() != null) { notification.DetailMessage.Add(ex.GetBaseException().Message); } return(false); } }
public override bool UpdateData(int id, ref DTO.SeatCushionMng.SeatCushion dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (SeatCushionMngEntities context = CreateContext()) { SeatCushion dbItem = null; if (id == 0) { dbItem = new SeatCushion(); context.SeatCushion.Add(dbItem); } else { dbItem = context.SeatCushion.FirstOrDefault(o => o.SeatCushionID == id); } if (dbItem == null) { notification.Message = "Back cushion 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); // processing image if (dtoItem.ImageFile_HasChange) { dbItem.ImageFile = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.ImageFile_NewFile, dtoItem.ImageFile); } if (id <= 0) { // generate code using (DbContextTransaction scope = context.Database.BeginTransaction()) { context.Database.ExecuteSqlCommand("SELECT * FROM SeatCushion WITH (TABLOCKX, HOLDLOCK)"); try { var newCode = context.SeatCushionMng_function_GenerateCode().FirstOrDefault(); if (newCode != "*") { dbItem.SeatCushionUD = newCode; } else { throw new Exception("Auto generated code exceed maximum option: [Z]"); } context.SaveChanges(); } catch (Exception ex) { throw ex; } finally { scope.Commit(); } } } else { context.SaveChanges(); } // Handle notification missing information. string emailSubject = (id == 0) ? "TASK REQUEST [CREATE SEAT CUSHION]" : "TASK REQUEST [UPDATE SEAT CUSHION]"; string emailBody = string.Empty; if (!IsNullPropertiesSeatCushion(dbItem, ref emailBody)) { SendToEmailNotification(context, emailSubject, emailBody); } dtoItem = GetData(dbItem.SeatCushionID, 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 override bool UpdateData(int id, ref DTO.SubMaterialOptionMng.SubMaterialOption dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; int number; string indexName; try { using (SubMaterialOptionMngEntities context = CreateContext()) { SubMaterialOption dbItem = null; if (id == 0) { dbItem = new SubMaterialOption(); context.SubMaterialOption.Add(dbItem); } else { dbItem = context.SubMaterialOption.FirstOrDefault(o => o.SubMaterialOptionID == id); } if (dbItem == null) { notification.Message = "Sub material option 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); } context.SaveChanges(); dtoItem = GetData(dbItem.SubMaterialOptionID, 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 == "SubMaterialColorUnique") { notification.Message = "The combination of Sub Material and Sub 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); } }
public void DTO2DB_ProductBreakDown(DTO.ProductBreakDownData dtoItem, ref ProductBreakDown dbItem, string tempFile, int userId) { // ProductBreakDown AutoMapper.Mapper.Map <DTO.ProductBreakDownData, ProductBreakDown>(dtoItem, dbItem); // ProductBreakDown: Category [Progress on Database] foreach (var dbCategory in dbItem.ProductBreakDownCategory.ToArray()) { if (!dtoItem.ProductBreakDownCategory.Select(o => o.ProductBreakDownCategoryID).Contains(dbCategory.ProductBreakDownCategoryID)) { // Category image foreach (var dbCategoryImage in dbCategory.ProductBreakDownCategoryImage.ToArray()) { if (!string.IsNullOrEmpty(dbCategoryImage.FileUD)) { // Remove Files fwFactory.RemoveImageFile(dbCategoryImage.FileUD); } // Remove ProductBreakDownCategoryImage dbCategory.ProductBreakDownCategoryImage.Remove(dbCategoryImage); } // Category type foreach (var dbCategoryType in dbCategory.ProductBreakDownCategoryType.ToArray()) { // Detail foreach (var dbDetail in dbCategoryType.ProductBreakDownDetail.ToArray()) { dbCategoryType.ProductBreakDownDetail.Remove(dbDetail); } dbCategory.ProductBreakDownCategoryType.Remove(dbCategoryType); } // Remove ProductBreakDownCategory dbItem.ProductBreakDownCategory.Remove(dbCategory); } } // ProductBreakDown: Category [Progress on DTO] foreach (var dtoCategory in dtoItem.ProductBreakDownCategory) { ProductBreakDownCategory dbCategory; if (dtoCategory.ProductBreakDownCategoryID < 0) { dbCategory = new ProductBreakDownCategory(); dbItem.ProductBreakDownCategory.Add(dbCategory); } else { dbCategory = dbItem.ProductBreakDownCategory.FirstOrDefault(o => o.ProductBreakDownCategoryID == dtoCategory.ProductBreakDownCategoryID); } if (dbCategory != null) { AutoMapper.Mapper.Map <DTO.ProductBreakDownCategoryData, ProductBreakDownCategory>(dtoCategory, dbCategory); // Category image foreach (var dbCategoryImage in dbCategory.ProductBreakDownCategoryImage.ToArray()) { if (!dtoCategory.ProductBreakDownCategoryImage.Select(o => o.ProductBreakDownCategoryImageID).Contains(dbCategoryImage.ProductBreakDownCategoryImageID)) { if (!string.IsNullOrEmpty(dbCategoryImage.FileUD)) { fwFactory.RemoveImageFile(dbCategoryImage.FileUD); } dbCategory.ProductBreakDownCategoryImage.Remove(dbCategoryImage); } } // Category type foreach (var dbCategoryType in dbCategory.ProductBreakDownCategoryType.ToArray()) { if (!dtoCategory.ProductBreakDownCategoryType.Select(o => o.ProductBreakDownCategoryTypeID).Contains(dbCategoryType.ProductBreakDownCategoryTypeID)) { // Remove detail foreach (var dbDetail in dbCategoryType.ProductBreakDownDetail.ToArray()) { dbCategoryType.ProductBreakDownDetail.Remove(dbDetail); } dbCategory.ProductBreakDownCategoryType.Remove(dbCategoryType); } } // Category image foreach (var dtoCategoryImage in dtoCategory.ProductBreakDownCategoryImage) { ProductBreakDownCategoryImage dbCategoryImage; if (dtoCategoryImage.ProductBreakDownCategoryImageID < 0) { dbCategoryImage = new ProductBreakDownCategoryImage(); dbCategory.ProductBreakDownCategoryImage.Add(dbCategoryImage); } else { dbCategoryImage = dbCategory.ProductBreakDownCategoryImage.FirstOrDefault(o => o.ProductBreakDownCategoryImageID == dtoCategoryImage.ProductBreakDownCategoryImageID); } if (dbCategoryImage != null) { // Progress category image if (dtoCategoryImage.HasChange.HasValue && dtoCategoryImage.HasChange.Value) { dbCategoryImage.FileUD = fwFactory.CreateFilePointer(tempFile, dtoCategoryImage.NewFile, dtoCategoryImage.FileUD, dtoCategoryImage.FriendlyName); } AutoMapper.Mapper.Map <DTO.ProductBreakDownCategoryImageData, ProductBreakDownCategoryImage>(dtoCategoryImage, dbCategoryImage); } } // Category type foreach (var dtoCategoryType in dtoCategory.ProductBreakDownCategoryType) { ProductBreakDownCategoryType dbCategoryType; if (dtoCategoryType.ProductBreakDownCategoryTypeID < 0) { dbCategoryType = new ProductBreakDownCategoryType(); dbCategory.ProductBreakDownCategoryType.Add(dbCategoryType); } else { dbCategoryType = dbCategory.ProductBreakDownCategoryType.FirstOrDefault(o => o.ProductBreakDownCategoryTypeID == dtoCategoryType.ProductBreakDownCategoryTypeID); } if (dbCategoryType != null) { AutoMapper.Mapper.Map <DTO.ProductBreakDownCategoryTypeData, ProductBreakDownCategoryType>(dtoCategoryType, dbCategoryType); foreach (var dbDetail in dbCategoryType.ProductBreakDownDetail.ToArray()) { if (!dtoCategoryType.ProductBreakDownDetail.Select(s => s.ProductBreakDownDetailID).Contains(dbDetail.ProductBreakDownDetailID)) { dbCategoryType.ProductBreakDownDetail.Remove(dbDetail); } } foreach (var dtoDetail in dtoCategoryType.ProductBreakDownDetail) { ProductBreakDownDetail dbDetail; if (dtoDetail.ProductBreakDownDetailID <= 0) { dbDetail = new ProductBreakDownDetail(); dbCategoryType.ProductBreakDownDetail.Add(dbDetail); } else { dbDetail = dbCategoryType.ProductBreakDownDetail.FirstOrDefault(o => o.ProductBreakDownDetailID == dtoDetail.ProductBreakDownDetailID); } if (dbDetail != null) { AutoMapper.Mapper.Map <DTO.ProductBreakDownDetailData, ProductBreakDownDetail>(dtoDetail, dbDetail); } } } } } } }
public override bool UpdateData(int userId, int id, ref object dtoItem1, out Notification notification) { DTO.CostInvoice2 dtoItem = ((Newtonsoft.Json.Linq.JObject)dtoItem1).ToObject <DTO.CostInvoice2>(); notification = new Notification(); notification.Type = NotificationType.Success; try { using (var context = CreateContext()) { CostInvoice2 dbItem; if (id > 0) { dbItem = context.CostInvoice2.FirstOrDefault(s => s.CostInvoice2ID == id); if (dbItem == null) { notification.Type = NotificationType.Error; notification.Message = "Can not find data"; return(false); } } else { dbItem = new CostInvoice2(); dbItem.CostInvoice2UD = (context.CostInvoice2.Count() + 1).ToString().PadLeft(10, '0'); context.CostInvoice2.Add(dbItem); } //upload file Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; if (dtoItem.File_HasChange.HasValue && dtoItem.File_HasChange.Value) { dtoItem.RelatedDocumentFile = fwFactory.CreateFilePointer(tempFolder, dtoItem.File_NewFile, dtoItem.RelatedDocumentFile, dtoItem.FriendlyName); } // converter.DTO2DB_CostInvoice2(dtoItem, ref dbItem); dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; dbItem.InvoiceDate = dtoItem.InvoiceDate.ConvertStringToDateTime(); dbItem.DueDate = dtoItem.DueDate.ConvertStringToDateTime(); dbItem.PaidDate = dtoItem.PaidDate.ConvertStringToDateTime(); context.CostInvoice2Client.Local.Where(o => o.CostInvoice2 == null).ToList().ForEach(o => context.CostInvoice2Client.Remove(o)); context.CostInvoice2Factory.Local.Where(o => o.CostInvoice2 == null).ToList().ForEach(o => context.CostInvoice2Factory.Remove(o)); context.SaveChanges(); dtoItem1 = GetData(dbItem.CostInvoice2ID, out notification); } return(true); } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { notification.DetailMessage.Add(ex.InnerException.Message); } return(false); } }
public override bool UpdateData(int id, ref DTO.FrameMaterialOptionMng.FrameMaterialOption dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; int number; string indexName; try { using (FrameMaterialOptionMngEntities context = CreateContext()) { FrameMaterialOption dbItem = null; if (id == 0) { dbItem = new FrameMaterialOption(); dbItem.CreatedBy = dtoItem.UpdatedBy; dbItem.CreatedDate = System.DateTime.Now; context.FrameMaterialOption.Add(dbItem); } else { dbItem = context.FrameMaterialOption.FirstOrDefault(o => o.FrameMaterialOptionID == id); } if (dbItem == null) { notification.Message = "Frame material option 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); } // save data converter.DTO2BD(dtoItem, ref dbItem); context.FrameMaterialOptionMaterialOption.Local.Where(o => o.FrameMaterialOption == null).ToList().ForEach(o => context.FrameMaterialOptionMaterialOption.Remove(o)); dbItem.UpdatedBy = dtoItem.UpdatedBy; dbItem.UpdatedDate = System.DateTime.Now; context.SaveChanges(); // 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 FRAME MATERIAL OPTION]" : "TASK REQUEST [UPDATE FRAME MATERIAL OPTION]"; string emailBody = string.Empty; if (!IsNullPropertiesFrameMaterialOption(dbItem, ref emailBody)) { SendToEmailNotification(context, emailSubject, emailBody); } dtoItem = GetData(dbItem.FrameMaterialOptionID, 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 == "IX_FrameMaterialOption") { notification.Message = "The combination of Frame Material and Frame 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); } }
public override bool UpdateData(int id, ref DTO.UserMng.UserProfile dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; int number; string indexName; try { using (UserMngEntities context = CreateContext()) { UserProfile dbItem = null; if (id == 0) { dbItem = new UserProfile(); context.UserProfile.Add(dbItem); dbItem.CreatedDate = DateTime.Now; dbItem.CreatedBy = dtoItem.UpdatedBy; } else { dbItem = context.UserProfile.FirstOrDefault(o => o.UserId == id); } if (dbItem == null) { notification.Message = "User 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.DTO2DB(dtoItem, ref dbItem); // remove orphans context.UserPermission.Local.Where(o => o.UserProfile == null).ToList().ForEach(o => context.UserPermission.Remove(o)); context.UserFactoryAccess.Local.Where(o => o.UserProfile == null).ToList().ForEach(o => context.UserFactoryAccess.Remove(o)); context.SaveChanges(); dbItem.UserUD = dbItem.UserId.ToString(); context.SaveChanges(); // processing image if (dtoItem.PersonalPhoto_HasChange) { dbItem.PersonalPhoto = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.PersonalPhoto_NewFile, dtoItem.PersonalPhoto); } if (dtoItem.SignatureImage_HasChange) { dbItem.SignatureImage = fwFactory.CreateFilePointer(this._TempFolder, dtoItem.SignatureImage_NewFile, dtoItem.SignatureImage); } context.SaveChanges(); dtoItem = GetData(dbItem.UserId, 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 == 2627) { switch (indexName) { case "UserUDUnique": notification.Message = "Duplicate user code"; break; default: notification.Message = dEx.Message; break; } } else { notification.Message = dEx.Message; } return(false); } 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 Notification notification) { notification = new Notification { Type = NotificationType.Success }; DTO.PurchaseQuotationDTO dtoPurchaseQuotation = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.PurchaseQuotationDTO>(); try { // 1. Check validation validFrom and validTo var validFrom = dtoPurchaseQuotation.ValidFrom.ConvertStringToDateTime(); var validTo = dtoPurchaseQuotation.ValidTo.ConvertStringToDateTime(); // 1.1. Case validFrom not value if (!validFrom.HasValue) { notification.Type = NotificationType.Error; notification.Message = "Valid From is invalid!"; return(false); } // 1.2. Compare if (validTo.HasValue) { if (validTo.Value.CompareTo(validFrom.Value) < 0) { notification.Type = NotificationType.Error; notification.Message = "Valid From is less than Valid To!"; return(false); } } using (var context = CreatContext()) { PurchaseQuotation dbItem; if (id == 0) { dbItem = new PurchaseQuotation(); context.PurchaseQuotation.Add(dbItem); } else { dbItem = context.PurchaseQuotation.Where(o => o.PurchaseQuotationID == id).FirstOrDefault(); } if (dbItem == null) { notification.Type = NotificationType.Error; notification.Message = "Data Not Found !"; return(false); } else { //converter converter.DTO2DB_PurchaseQuatation(dtoPurchaseQuotation, ref dbItem); //upload file Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; if (dtoPurchaseQuotation.File_HasChange.HasValue && dtoPurchaseQuotation.File_HasChange.Value) { dbItem.AttachedFile = fwFactory.CreateFilePointer(tempFolder, dtoPurchaseQuotation.File_NewFile, dtoPurchaseQuotation.AttachedFile, dtoPurchaseQuotation.FriendlyName); } //Remove context.PurchaseQuotationDetail.Local.Where(o => o.PurchaseQuotation == null).ToList().ForEach(o => context.PurchaseQuotationDetail.Remove(o)); int?companyID = fwFactory.GetCompanyID(userId); dbItem.CompanyID = companyID; dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; if (id == 0) { dbItem.PurchaseQuotationUD = context.PurchaseQuotationMng_function_GeneratePurchaseQuotationUD().FirstOrDefault(); dbItem.CreatedBy = userId; dbItem.CreatedDate = DateTime.Now; } /// cuong.tran: ProductionFrameWeight - start foreach (var item in dtoPurchaseQuotation.PurchaseQuotationDetailDTOs) { /// Only material is component if (item.ProductionItemTypeID == 1 && item.FrameWeight.HasValue) { var dtoFrameWeight = context.ProductionFrameWeight.FirstOrDefault(o => o.ProductionItemID == item.ProductionItemID); if (dtoFrameWeight == null) { // Insert table ProductionFrameWeight ProductionFrameWeight dbFrameWeight = new ProductionFrameWeight(); context.ProductionFrameWeight.Add(dbFrameWeight); dbFrameWeight.ProductionItemID = item.ProductionItemID; dbFrameWeight.FrameWeight = item.FrameWeight; dbFrameWeight.UpdatedBy = userId; dbFrameWeight.UpdatedDate = DateTime.Now; context.SaveChanges(); // Insert table ProductionFrameWeightHistory ProductionFrameWeightHistory dbFrameWeightHistory = new ProductionFrameWeightHistory(); context.ProductionFrameWeightHistory.Add(dbFrameWeightHistory); dbFrameWeightHistory.ProductionFrameWeightID = dbFrameWeight.ProductionFrameWeightID; dbFrameWeightHistory.FrameWeight = item.FrameWeight; dbFrameWeightHistory.UpdatedBy = userId; dbFrameWeightHistory.UpdatedDate = DateTime.Now; context.SaveChanges(); } } } /// cuong.tran: ProductionFrameWeight - e n d //Save context.SaveChanges(); dtoItem = GetData(dbItem.PurchaseQuotationID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; return(false); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification) { notification = new Notification() { Type = NotificationType.Success }; DTO.QualityDocumentDTO dtoItems = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.QualityDocumentDTO>(); try { using (var context = CreatContex()) { QualityDocument dbItem; if (id == 0) { dbItem = new QualityDocument(); context.QualityDocument.Add(dbItem); } else { dbItem = context.QualityDocument.Where(o => o.QualityDocumentID == id).FirstOrDefault(); } if (dbItem == null) { notification.Message = "Data Not Found !"; return(false); } else { converter.DTO2DB_QualityDocument(dtoItems, ref dbItem); //upload file Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; if (dtoItems.File_HasChange.HasValue && dtoItems.File_HasChange.Value) { dbItem.AttachedFile = fwFactory.CreateFilePointer(tempFolder, dtoItems.File_NewFile, dtoItems.AttachedFile, dtoItems.FriendlyName); } dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; //save context.SaveChanges(); dtoItem = GetData(dbItem.QualityDocumentID, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; notification.DetailMessage.Add(ex.Message); if (ex.GetBaseException() != null) { notification.DetailMessage.Add(ex.GetBaseException().Message); } } return(true); }
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 Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.ReceiptNoteEditResult dtoReceipt = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.ReceiptNoteEditResult>(); try { //get companyID Module.Framework.DAL.DataFactory fw_factory = new Framework.DAL.DataFactory(); int?companyID = fw_factory.GetCompanyID(userId); using (var context = CreateContext()) { //Check Client if (dtoReceipt.ReceiptNoteTypeID == 2) { foreach (var item in dtoReceipt.receiptNoteClientResults) { if (item.FactoryRawMaterialID == null) { throw new Exception("missing Client !!!"); } } } //if (dtoReceipt.ReceiptNoteTypeID == 3) //{ // foreach (var item in dtoReceipt.receiptNoteOtherResults) // { // if (item.EmployeeID == null) // { // throw new Exception("missing Client !!!"); // } // } //} if (dtoReceipt.ReceiptNoteTypeID == 4 || dtoReceipt.ReceiptNoteTypeID == 3) { dtoReceipt.SupplierID = null; dtoReceipt.SupplierNM = null; dtoReceipt.SupplierUD = null; } ReceiptNote dbItem = null; if (id == 0) { if (dtoReceipt.StatusID == 2 || dtoReceipt.StatusID == 3) { throw new Exception("Set Status open to Save !!!"); } dbItem = new ReceiptNote(); context.ReceiptNote.Add(dbItem); //Automatically generate code if (dtoReceipt.ReceiveTypeID == 1)// Receive type Cash { int year = DateTime.Now.Year; string month = DateTime.Now.Month.ToString().PadLeft(2, '0'); string receipt_pattern = "PT" + "_" + year.ToString().Substring(2) + month; var db_receiptNo = context.ReceiptNote.Where(o => o.ReceiptNoteNo.Substring(0, 7) == receipt_pattern).OrderByDescending(o => o.ReceiptNoteNo); if (db_receiptNo.ToList().Count() == 0) { dtoReceipt.ReceiptNoteNo = receipt_pattern + "_" + "001"; } else { var select_receipt = db_receiptNo.FirstOrDefault(); int iNo = Convert.ToInt32(select_receipt.ReceiptNoteNo.Substring(8, 3)) + 1; dtoReceipt.ReceiptNoteNo = select_receipt.ReceiptNoteNo.Substring(0, 7) + "_" + iNo.ToString().PadLeft(3, '0'); } } else if (dtoReceipt.ReceiveTypeID == 2)// Receive type Bank { int year = DateTime.Now.Year; string month = DateTime.Now.Month.ToString().PadLeft(2, '0'); string receipt_pattern = "BC" + "_" + year.ToString().Substring(2) + month; var db_receiptNo = context.ReceiptNote.Where(o => o.ReceiptNoteNo.Substring(0, 7) == receipt_pattern).OrderByDescending(o => o.ReceiptNoteNo); if (db_receiptNo.ToList().Count() == 0) { dtoReceipt.ReceiptNoteNo = receipt_pattern + "_" + "001"; } else { var select_receipt = db_receiptNo.FirstOrDefault(); int iNo = Convert.ToInt32(select_receipt.ReceiptNoteNo.Substring(8, 3)) + 1; dtoReceipt.ReceiptNoteNo = select_receipt.ReceiptNoteNo.Substring(0, 7) + "_" + iNo.ToString().PadLeft(3, '0'); } } } else { dbItem = context.ReceiptNote.Where(o => o.ReceiptNoteID == id).FirstOrDefault(); if (dbItem.ReceiptNoteTypeID != dtoReceipt.ReceiptNoteTypeID) { throw new Exception("Can't change Receipt Note type !!!"); } } if (dbItem == null) { notification.Message = "data not found!"; return(false); } else { //check status /* * WorkOrderStatusID : * 1 : Open * 2 : Confimred */ if (dbItem.StatusID == 2 || dbItem.StatusID == 3) { throw new Exception("Can't Update because receipt comfirmed !!!"); } if (dtoReceipt.StatusID == 2 && dtoReceipt.ReceiptNoteTypeID == 1) { ValidatePayment(dbItem.ReceiptNoteID, 2); } //convert dto to db converter.DTO2DB_Update(dtoReceipt, ref dbItem, userId); //upload file Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; if (dtoReceipt.File_HasChange.HasValue && dtoReceipt.File_HasChange.Value) { dbItem.AttachedFile = fwFactory.CreateFilePointer(tempFolder, dtoReceipt.File_NewFile, dtoReceipt.AttachedFile, dtoReceipt.FriendlyName); } if (id == 0) { dbItem.CreateDate = DateTime.Now; dbItem.CreateBy = userId; } else { dbItem.UpdateDate = DateTime.Now; dbItem.UpdateBy = userId; } //remove orphan context.ReceiptNoteClient.Local.Where(o => o.ReceiptNote == null).ToList().ForEach(o => context.ReceiptNoteClient.Remove(o)); context.ReceiptNoteInvoice.Local.Where(o => o.ReceiptNote == null).ToList().ForEach(o => context.ReceiptNoteInvoice.Remove(o)); context.ReceiptNoteOther.Local.Where(o => o.ReceiptNote == null).ToList().ForEach(o => context.ReceiptNoteOther.Remove(o)); //save data context.SaveChanges(); dtoItem = GetData(userId, dbItem.ReceiptNoteID, null, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; return(false); } }
public bool Update(int userId, int id, ref object dto, out Notification notification) { DTO.QCReportDTO dtoItem = ((Newtonsoft.Json.Linq.JObject)dto).ToObject <DTO.QCReportDTO>(); notification = new Notification() { Type = NotificationType.Success }; try { using (QCReportEntities context = CreateContext()) { QCReport dbItem = null; if (id > 0) { dbItem = context.QCReport.FirstOrDefault(s => s.QCReportID == id); if (dbItem == null) { notification = new Notification() { Type = NotificationType.Error, Message = "Can not find data" }; return(false); } } else { dbItem = new QCReport(); context.QCReport.Add(dbItem); } // add QCReportImage foreach (var item in dtoItem.QCReportImageDTOs) { if (item.ScanHasChange) { if (string.IsNullOrEmpty(item.ScanNewFile)) { fwFactory.RemoveFile(item.FileUD); } else { item.FileUD = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", item.ScanNewFile, item.FileUD); } } } converter.DTO2DB_QCReport(dtoItem, ref dbItem); // product image if (dtoItem.ScanHasChange) { dbItem.ProductImage = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoItem.ScanNewFile, dtoItem.ProductImage); } if (dtoItem.ReportScanHasChange) { dbItem.ReportFile = fwFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoItem.ReportScanNewFile, dtoItem.ReportFile); } dbItem.UpdatedBy = userId; dbItem.UpdatedDate = DateTime.Now; context.QCReportSummary.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportSummary.Remove(s)); context.QCReportDetail.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportDetail.Remove(s)); context.QCReportDefect.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportDefect.Remove(s)); context.QCReportImage.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportImage.Remove(s)); context.QCReportTestEnvironment.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportTestEnvironment.Remove(s)); context.QCReportFactoryOrderDetail.Local.Where(o => o.QCReport == null).ToList().ForEach(s => context.QCReportFactoryOrderDetail.Remove(s)); context.SaveChanges(); //Create code of id dbItem.QCReportUD = "QC" + dbItem.QCReportID.ToString("D8"); context.SaveChanges(); if (id == 0) { string emailSubject = ""; string emailBody = ""; string url = ""; url = this.frontendURL + "QCReportMng/Edit/" + dbItem.QCReportID.ToString(); emailSubject += "New QC report - " + "[" + dtoItem.ClientUD + "]" + " / " + "[" + dtoItem.FactoryUD + "]" + " - " + dtoItem.ArticleCode + " - " + dtoItem.Description; emailBody += "New QC Report:"; emailBody += Environment.NewLine + "Click <a href='" + url + "'>here</a> to link to QC Report:" + url; var QCReportMenber = context.QCReportMng_QCReportGroupMember_View.ToList(); var ClientManager = context.QCReportMng_ClientManager_View.Where(o => o.ClientID == dtoItem.ClientID).FirstOrDefault(); List <int?> UserIDs = new List <int?>(); UserIDs.Add(ClientManager.AccManagerID); UserIDs.Add(ClientManager.AccManagerAssitantID); UserIDs.Add(ClientManager.VNMerchandiserID); UserIDs.Add(ClientManager.VNMerchandiserAssitantID); string sendToEmail = ""; if (QCReportMenber.Count() > 0) { foreach (var item in QCReportMenber) { if (sendToEmail != "") { sendToEmail += ";" + item.Email; } else { sendToEmail = item.Email; } UserIDs.Add(item.UserID); } } if (ClientManager.AccManagerEmail != "") { if (sendToEmail != "") { sendToEmail += ";" + ClientManager.AccManagerEmail; } else { sendToEmail = ClientManager.AccManagerEmail; } } if (ClientManager.AccManagerAssitantEmail != "") { if (sendToEmail != "") { sendToEmail += ";" + ClientManager.AccManagerAssitantEmail; } else { sendToEmail = ClientManager.AccManagerAssitantEmail; } } if (ClientManager.VNMerchandiserEmail != "") { if (sendToEmail != "") { sendToEmail += ";" + ClientManager.VNMerchandiserEmail; } else { sendToEmail = ClientManager.VNMerchandiserEmail; } } if (ClientManager.VNMerchandiserAssitantEmail != "") { if (sendToEmail != "") { sendToEmail += ";" + ClientManager.VNMerchandiserAssitantEmail; } else { sendToEmail = ClientManager.VNMerchandiserAssitantEmail; } } SendNotification(emailSubject, emailBody, sendToEmail, UserIDs); } dto = GetData(dbItem.QCReportID, dbItem.SaleOrderDetailID, dbItem.FactoryID, null, null, null, out notification).Data; } return(true); } catch (Exception ex) { notification = new Notification() { Type = NotificationType.Error, Message = ex.Message }; return(false); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.PurchaseInvoiceDTO dtoPurchaseInvoice = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.PurchaseInvoiceDTO>(); try { using (PurchaseInvoiceMngEntities context = CreateContext()) { PurchaseInvoice dbItem = null; if (id == 0) { dbItem = new PurchaseInvoice(); context.PurchaseInvoice.Add(dbItem); } else { dbItem = context.PurchaseInvoice.Where(o => o.PurchaseInvoiceID == id).FirstOrDefault(); } if (dbItem == null) { notification.Message = "data not found!"; return(false); } else { if (!dtoPurchaseInvoice.PurchaseInvoiceTypeID.HasValue) { throw new Exception("Please select type of purchasing invoice"); } //upload file Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory(); string tempFolder = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\"; if (dtoPurchaseInvoice.File_HasChange.HasValue && dtoPurchaseInvoice.File_HasChange.Value) { dtoPurchaseInvoice.AttachedFile = fwFactory.CreateFilePointer(tempFolder, dtoPurchaseInvoice.File_NewFile, dtoPurchaseInvoice.AttachedFile, dtoPurchaseInvoice.FriendlyName); } //convert dto to db converter.DTO2DB_PurchaseInvoice(dtoPurchaseInvoice, ref dbItem, userId); if (id == 0) { dbItem.PurchaseInvoiceStatusID = 1; dbItem.SetStatusBy = userId; dbItem.SetStatusDate = DateTime.Now; } //remove orphan context.PurchaseInvoiceDetail.Local.Where(o => o.PurchaseInvoice == null).ToList().ForEach(o => context.PurchaseInvoiceDetail.Remove(o)); //save data context.SaveChanges(); //generate purchase invoice code if (string.IsNullOrEmpty(dbItem.PurchaseInvoiceUD)) { context.PurchaseInvoiceMng_function_GeneratePurchaseInvoiceUD(dbItem.PurchaseInvoiceID, dbItem.PurchaseInvoiceDate.Value.Year, dbItem.PurchaseInvoiceDate.Value.Month); } //get return data dtoItem = GetData(userId, dbItem.PurchaseInvoiceID, null, out notification).Data; return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; return(false); } }