public MemoryStream Execute() { var productsDict = SupplyOrderCalc.CreateProductList(context); XmlMedicineSupplyModel supply = new XmlMedicineSupplyModel(); foreach (var p in productsDict) { var model = AutoMapper.Mapper.Map <XmlMedicineModel>(context.Medicines.Single(s => s.ID == p.Key)); model.Quantity = (uint)p.Value; supply.Medicines.Add(model); } MemoryStream stream = null; try { stream = serializer.Serialize(supply); fileCopy.Create(stream, "store_order_", ".xml", "XML", "created_orders"); stream.Position = 0; } catch (Exception ex) { logger.LogError(ex.Message, ex); } return(stream); }
public UploadResultViewModel Execute(IFormFile xmlFile) { UploadResultViewModel result = new UploadResultViewModel(); try { if (!validExtensions.Any(e => e.Contains(xmlFile.ContentType))) { throw new UploadedFileWrongFormatException(xmlFile.ContentType); } using (MemoryStream stream = new MemoryStream()) { xmlFile.CopyTo(stream); result = UpdateStore(serializer.Deserialize(stream)); fileCopy.Create(stream, "store_update_", ".xml", "XML", "done_updates"); } } catch (Exception ex) { logger.LogError(ex, ex.Message); result.Message = ex.Message; result.Succes = false; } finally { string outcome = result.Succes ? "SUCCESS" : "FAILURE"; logger.LogInformation("External Drugstore was supplied with" + outcome); } return(result); }
public ResultViewModel <Dictionary <string, object> > Execute(IFormFile xmlFile) { ResultViewModel <Dictionary <string, object> > result = new ResultViewModel <Dictionary <string, object> >(); try { if (!validExtensions.Any(e => e.Contains(xmlFile.ContentType))) { throw new UploadedFileWrongFormatException(xmlFile.ContentType); } using (MemoryStream stream = new MemoryStream()) { xmlFile.CopyToAsync(stream).Wait(); stream.Position = 0; var supply = serializer.Deserialize(stream); result = UpdateStore(supply); fileCopy.Create(stream, "external_drugstore_sale_", ".xml", "XML", "external_drugstore_sale_history"); } } catch (FileCopyCreationException ex) { logger.LogError(ex, ex.Message); } catch (Exception ex) { if (ex is MedicineNotFoundException || ex is OnStockMedicineQuantityException) { logger.LogError(ex, ex.Message); result.Succes = false; result.Message = ex.Message; } else { string message = "UKNOWN EXCEPTION: " + ex.Message; logger.LogError(ex, message); result.Succes = false; result.Message = message; } } finally { string outcome = result.Succes ? "SUCCEEDED" : "FAILED"; logger.LogInformation("External Drugstore sold medicines update " + outcome); } return(result); }