Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        public LocalStorage(Models.Storage storage, ILogger <LocalStorage> logger)
        {
            Id          = storage.Id;
            Type        = storage.Type;
            StoragePath = storage.StoragePath;
            IsDefault   = storage.IsDefault;

            _logger = logger;
        }
Exemplo n.º 4
0
        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}");
            }
        }
Exemplo n.º 5
0
        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);
        }