private bool IsNullPropertiesMaterialOption(MaterialOption materialOption, ref string emailBody) { bool isNotNull = true; // Set content notification. emailBody += "Material Option ID: " + materialOption.MaterialOptionID; emailBody += Environment.NewLine + "Material Option UD: " + materialOption.MaterialOptionUD; emailBody += Environment.NewLine + "Material Option NM: " + materialOption.MaterialOptionNM; // Season is null or not null. if (string.IsNullOrEmpty(materialOption.Season)) { emailBody += Environment.NewLine + "Season: Current value is null."; isNotNull = false; } else { emailBody += Environment.NewLine + "Season: " + materialOption.Season; } // Image is null or not null. if (string.IsNullOrEmpty(materialOption.ImageFile)) { emailBody += Environment.NewLine + "Image: Current value is null."; isNotNull = false; } else { emailBody += Environment.NewLine + "Image: " + materialOption.ImageFile; } return(isNotNull); }
public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (MaterialOptionMngEntities context = CreateContext()) { MaterialOption dbItem = context.MaterialOption.FirstOrDefault(o => o.MaterialOptionID == id); if (dbItem == null) { notification.Message = "Material not found!"; return(false); } else { if (!string.IsNullOrEmpty(dbItem.ImageFile)) { // remove image fwFactory.RemoveImageFile(dbItem.ImageFile); } context.MaterialOption.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public void DTO2DB(DTO.MaterialOptionMng.MaterialOption dtoItem, ref MaterialOption dbItem) { AutoMapper.Mapper.Map <DTO.MaterialOptionMng.MaterialOption, MaterialOption>(dtoItem, dbItem); //dbItem.UpdatedDate = DateTime.Now; //if (dtoItem.MaterialOptionID == 0) //{ // dbItem.CreatedBy = dtoItem.CreatedBy; // dbItem.CreatedDate = DateTime.Now; //} // map child if (dtoItem.ProductGroups != null) { // map child rows foreach (DTO.MaterialOptionMng.ProductGroup dtoGroup in dtoItem.ProductGroups) { MaterialOptionProductGroup dbGroup; if (dtoGroup.MaterialOptionProductGroupID <= 0) { dbGroup = new MaterialOptionProductGroup(); dbItem.MaterialOptionProductGroup.Add(dbGroup); } else { dbGroup = dbItem.MaterialOptionProductGroup.FirstOrDefault(o => o.MaterialOptionProductGroupID == dtoGroup.MaterialOptionProductGroupID); } if (dbGroup != null) { AutoMapper.Mapper.Map <DTO.MaterialOptionMng.ProductGroup, MaterialOptionProductGroup>(dtoGroup, dbGroup); } } } if (dtoItem.MaterialOptionTestReports != null) { // check for child rows deleted foreach (var dbReport in dbItem.MaterialOptionTestReport.ToArray()) { if (!dtoItem.MaterialOptionTestReports.Select(o => o.MaterialOptionTestReportID).Contains(dbReport.MaterialOptionTestReportID)) { dbItem.MaterialOptionTestReport.Remove(dbReport); } } foreach (var dtoReport in dtoItem.MaterialOptionTestReports) { MaterialOptionTestReport dbReport; if (dtoReport.MaterialOptionTestReportID <= 0) { dbReport = new MaterialOptionTestReport(); dbItem.MaterialOptionTestReport.Add(dbReport); } else { dbReport = dbItem.MaterialOptionTestReport.FirstOrDefault(o => o.MaterialOptionTestReportID == dtoReport.MaterialOptionTestReportID); } if (dbReport != null) { AutoMapper.Mapper.Map <DTO.MaterialOptionMng.MaterialOptionTestReport, MaterialOptionTestReport>(dtoReport, dbReport); dbReport.UpdatedBy = dtoItem.UpdatedBy; dbReport.UpdatedDate = DateTime.Now; } } } }
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); } }