Esempio n. 1
0
 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);
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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());
        }
Esempio n. 4
0
 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;
     }
 }