Esempio n. 1
0
        public IActionResult Add([FromRoute] long fileId, [FromBody] FileBlockInfo fileBlockInfo)
        {
            FileBlock fileBlock = _db.FileBlocks.FirstOrDefault(fb => fb.FileId == fileId && fb.Number == fileBlockInfo.Number);

            using (MD5 md5Hash = MD5.Create())
            {
                byte[] rawContent = Convert.FromBase64String(fileBlockInfo.Value);

                if (fileBlock == null) //Create new fileBlock
                {
                    _db.FileBlocks.Add(new FileBlock()
                    {
                        FileId   = fileId,
                        Number   = fileBlockInfo.Number,
                        Content  = rawContent,
                        Checksum = MD5Utils.GetMd5Hash(md5Hash, rawContent.ToString())
                    });
                }
                else //Update existing fileBlock
                {
                    fileBlock.Content  = rawContent;
                    fileBlock.Checksum = MD5Utils.GetMd5Hash(md5Hash, rawContent.ToString());
                    _db.FileBlocks.Update(fileBlock);
                }

                _db.SaveChanges();
            }

            return(StatusCode((int)HttpStatusCode.OK));
        }
Esempio n. 2
0
        public File Add([FromBody] File file)
        {
            File createdFile = _db.Files.Add(new File()
            {
                Name             = file.Name,
                BlockSizeInBytes = file.BlockSizeInBytes,
                SizeInBytes      = file.SizeInBytes
            }).Entity;

            _db.SaveChanges();

            return(createdFile);
        }