public Error InsertOrUpdateProductCompliance(ProductComplianceModel productCompliance, string lockGuid) { Error error = ValidateModel(productCompliance); if (!error.IsError) { // Check that the lock is still current if (!db.IsLockStillValid(typeof(ProductCompliance).ToString(), productCompliance.Id, lockGuid)) { error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "ComplianceCategoryId"); } else { ProductCompliance temp = null; if (productCompliance.Id != 0) { temp = db.FindProductCompliance(productCompliance.Id); } if (temp == null) { temp = new ProductCompliance(); } Mapper.Map(productCompliance, temp); db.InsertOrUpdateProductCompliance(temp); productCompliance.Id = temp.Id; } } return(error); }
public ProductComplianceModel MapToModel(ProductCompliance item) { if (item == null) { return(null); } else { var newItem = Mapper.Map <ProductCompliance, ProductComplianceModel>(item); if (item.LOVItem_ComplianceCategory != null) { newItem.ComplianceCategoryText = item.LOVItem_ComplianceCategory.ItemText; } if (item.LOVItem_Market != null) { newItem.MarketNameText = item.LOVItem_Market.ItemText; } // Add the attachments foreach (var attachment in item.ProductComplianceAttachments) { var newAttachment = new ProductComplianceAttachmentModel { Id = attachment.Id, ProductComplianceId = attachment.ProductComplianceId, MediaId = attachment.MediaId, FileName = attachment.Medium.FileName, QualName = MediaServices.GetMediaFolder(-1, true) + attachment.Medium.FolderName + attachment.Medium.FileName }; newItem.Attachments.Add(newAttachment); if (!string.IsNullOrEmpty(newItem.AttachmentHtml)) { newItem.AttachmentHtml += "<br/>"; } newItem.AttachmentHtml += $"<a href=\"{newAttachment.QualName}\" target=\"_new\">{newAttachment.FileName}</a>"; } return(newItem); } }