public LibraryBusinessService(ILibraryDataService libraryDataService) { this.libraryDataService = libraryDataService; //HttpContext.Current.Request.Files }
private void RestoreAssetFromTxt(byte[] data, ILibraryDataService libraryDataService) { using (var stream = new MemoryStream(data)) { var txtData = string.Empty; using (var reader = new StreamReader(stream)) { txtData = reader.ReadToEnd(); } if (txtData.Substring(1, 4) != "List") { var asset = RestoreFromTxt(txtData); libraryDataService.AddAsset(asset); libraryDataService.SaveChanges(); return; } var assets = RestoreAssetsListFromTxt(txtData); libraryDataService.AddAssetsRange(assets); libraryDataService.SaveChanges(); } }
private void RestoreAssetFromXml(byte[] data, ILibraryDataService libraryDataService) { using (var stream = new MemoryStream(data)) { var xmlDocument = XDocument.Load(stream); if (xmlDocument.Elements().FirstOrDefault().Name == null) { throw new Exception("Incorrect file format"); } if (xmlDocument.Elements().FirstOrDefault().Name != "List") { var asset = RestoreFromXml(xmlDocument.Elements().FirstOrDefault()); libraryDataService.AddAsset(asset); libraryDataService.SaveChanges(); return; } var assets = RestoreAssetsListFromXml(xmlDocument); libraryDataService.AddAssetsRange(assets); libraryDataService.SaveChanges(); } }
public void RestoreDataFromFile(IFormFileCollection file, ILibraryDataService libraryDataService) { var fileExtension = Path.GetExtension(file[0].FileName); using (var stream = new MemoryStream()) { file[0].CopyTo(stream); byte[] data = stream.ToArray(); if (fileExtension == ".xml") { RestoreAssetFromXml(data, libraryDataService); return; } if (fileExtension == ".txt") { RestoreAssetFromTxt(data, libraryDataService); return; } throw new Exception("Incorrect file type"); } }
public AssetController(ILibraryDataService libraryDataService) { this._libraryDataService = libraryDataService; }
public BaseAssetController(ILibraryDataService libraryDataService, IImageHandlerService imageService, IHostingEnvironment appEnvironment) { this._libraryDataService = libraryDataService; this._imageService = imageService; this._appEnvironment = appEnvironment; }
public DataFileController(ILibraryDataService libraryDataService, IDataFileService dataFileService) { this._libraryDataService = libraryDataService; this._dataFileService = dataFileService; }
/// <summary> /// Constructor with Dependency Injection using Ninject /// </summary> /// <param name="dataService"></param> public LibraryApiController() { libraryDataService = new LibraryDataService(); }
public JournalController(ILibraryDataService libraryDataService, IImageHandlerService imageService, IHostingEnvironment appEnvironment) : base(libraryDataService, imageService, appEnvironment) { }