Exemple #1
0
        /// <summary>
        /// Update file
        /// </summary>
        /// <param name="id"></param>
        /// <param name="file"></param>
        /// <param name="formFile"></param>
        /// <returns></returns>
        public async Task <int> Update(int id, File file)
        {
            try
            {
                var oldFile = await Load(id);

                if (oldFile == null)
                {
                    throw new NotFoundException("File not found");
                }

                //Update old message fields
                oldFile.UpdateModifiedFields(file, ref _context);

                oldFile.UpdateDate = DateTime.Now;

                _context.Update(oldFile);

                await _context.SaveChangesAsync();

                return(oldFile.Id);
            }
            catch
            {
                throw;
            }
        }
        public async Task <IActionResult> Modify(Guid fileGuid, [FromBody] UploadFileDto changeData)
        {
            var file = await _dbContext.Files.FindAsync(fileGuid);

            if (file == null)
            {
                return(NotFound());
            }

            file.DisplayName = changeData.DisplayName;
            if (changeData.MimeType != null)
            {
                file.MimeType = changeData.MimeType;
                if (changeData.Content != null)
                {
                    file.Content = changeData.Content;
                }
            }

            _dbContext.Update(file);
            await _dbContext.SaveChangesAsync();

            return(NoContent());
        }