Example #1
0
        public async Task <Response <FileEdit, FileEditErrors> > CreateAsync(string fileId)
        {
            if (await _dbContext.FileEdits.AnyAsync(fe => fe.FileId == fileId))
            {
                return(new Response <FileEdit, FileEditErrors>(FileEditErrors.FileEditAlreadyExist));
            }

            var fileResponse = await _fileService.GetByIdAsync(fileId);

            if (fileResponse.HasError)
            {
                return(new Response <FileEdit, FileEditErrors>(FileEditErrors.FileEditConflict));
            }

            var file = fileResponse.Result;

            var newFileEdit = new FileEdit
            {
                FileId       = file.Id,
                FileName     = file.Name,
                Content      = file.Content,
                StartingHash = file.Hash,
                Hash         = file.Hash
            };

            await _dbContext.FileEdits.AddAsync(newFileEdit);

            await _dbContext.SaveChangesAsync();

            await _NotifyAsync(newFileEdit, FileEditNotifications.Created);

            return(new Response <FileEdit, FileEditErrors>(newFileEdit));
        }
Example #2
0
 public static object ToJsonObject(FileEdit fileEdit) => new
 {
     fileId   = fileEdit.FileId,
     fileName = fileEdit.FileName,
     content  = fileEdit.Content,
     hash     = fileEdit.Hash
 };
Example #3
0
 private async Task _NotifyAsync(FileEdit fileEdit, FileEditNotifications notification)
 {
     await _notificationService.NotifyAsync(
         notification,
         new FileEditNotification
     {
         FileId = fileEdit.FileId,
         Hash   = fileEdit.Hash
     });
 }