public async Task <IActionResult> PostStorage([FromBody] Models.Storage @storage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Storages.Add(@storage); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (StorageExists(@storage.StorageId)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetStorage", new { id = @storage.StorageId }, @storage)); }
public async Task <IActionResult> PutStorage([FromRoute] int id, [FromBody] Models.Storage @storage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != @storage.StorageId) { return(BadRequest()); } _context.Entry(@storage).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StorageExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public LocalStorage(Models.Storage storage, ILogger <LocalStorage> logger) { Id = storage.Id; Type = storage.Type; StoragePath = storage.StoragePath; IsDefault = storage.IsDefault; _logger = logger; }
private IStorage GetStorage(Models.Storage storage) { switch (storage.Type) { case StorageType.LocalStorage: return(new LocalStorage(storage, _logger)); default: throw new ArgumentException($"Invalid storage type: {storage.Type}"); } }
public Storage Get(string sql) { var res = dBService.SelectBySql(sql); if (res.Rows.Count == 0) { return(null); } Models.Storage stoModel = new Models.Storage() { Id = new Id(res.Rows[0].ItemArray[0] as string), Hash = (string)(res.Rows[0].ItemArray[1]), FileName = (string)(res.Rows[0].ItemArray[2]), FilePath = (string)(res.Rows[0].ItemArray[3]), StorageName = (string)(res.Rows[0].ItemArray[4]), VolumeId = new Id(res.Rows[0].ItemArray[5] as string), //Date = DateTime.Parse((string)(row.ItemArray[4])), }; return(stoModel); }