public static void Export(Stream xml, IObjectSpace os, Invoice invoice) { using (var writer = new StreamWriter(xml, Encoding.GetEncoding("windows-1251"))) { var serializer = new XmlSerializer(typeof(InvoiceXml)); var ns = new XmlSerializerNamespaces(); ns.Add("", ""); var mapper = new InvoiceXmlMapper(new ObjectSpaceEntityFactory(os)); var invoiceXml = mapper.Map(invoice); serializer.Serialize(writer, invoiceXml, ns); } }
public ActionResult <InvoiceXml> GetByGuid(Guid guid) { var result = GetEntities().FirstOrDefault(entity => entity.Guid == guid); if (result == null) { return(new NotFoundResult()); } var mapper = new InvoiceXmlMapper(new PlainEntityFactory()); var invoiceXml = mapper.Map(result); return(invoiceXml); }
public IActionResult Create(InvoiceXml invoiceXml) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var mapper = new InvoiceXmlMapper(new EntityFactory(_context)); var entity = mapper.Map(invoiceXml); OnCreating(entity); _context.Set <Invoice>().Add(entity); _context.SaveChanges(); //return CreatedAtAction(nameof(GetByGuid), new { guid = entity.Guid }, entity); return(Ok()); }
public static void Import(Stream xml, IObjectSpace os, CollectionSourceBase collection) { try { var serializer = new XmlSerializer(typeof(InvoiceXml)); var invoiceXml = (InvoiceXml)serializer.Deserialize(xml); var mapper = new InvoiceXmlMapper(new ObjectSpaceEntityFactory(os)); var invoice = mapper.Map(invoiceXml); os.CommitChanges(); collection.Add(invoice); } catch (Exception ex) { os.Rollback(); throw ex; } }