public static string ToXml(this RequestList requestList) { XmlSerializer xsSubmit = new XmlSerializer(typeof(RequestList)); System.IO.StringWriter sww = new System.IO.StringWriter(); XmlWriter writer = XmlWriter.Create(sww); xsSubmit.Serialize(writer, requestList); return(sww.ToString()); }
public static RequestList ConvertToXmlObject(List <Request> requests) { int i = 0; var result = new RequestList() { Requests = new RequestElement[requests.Count] }; foreach (var request in requests) { var listFiles = new List <FileDinhKem>(); if (request.Status == 0) //Chỉ lấy file của những ykcd được thêm mới { foreach (var file in request.Document.Files) { string path = $"{ConfigurationManager.AppSettings["Path_Upload"]}\\{file.FileName}"; if (System.IO.File.Exists(path)) { listFiles.Add(new FileDinhKem() { FileName = file.FileName, Content = System.IO.File.ReadAllBytes(path) }); } } } result.Requests[i] = new RequestElement { DocumentID = request.DocumentID, DocumentCode = request.Document.DocumentCode, ReleasedDate = request.Document.ReleaseDate, MainContent = request.Document.MainContent, SignerName = request.Document.SignerName, RequestID = request.RequestID, PerformID = request.PerformID, RequestContent = request.RequestContent, RequiredDate = request.RequiredDate, RequesterID = request.RequesterID, RequesterName = request.RequesterName, Status = request.Status, FinishedOnDate = request.FinishedOnDate, IsDeleted = request.IsDeleted, DanhSachFile = listFiles?.ToArray() }; i++; } return(result); }