internal static ClipboardGetData CreateFromEntity(ClipboardContentEntity cc, FileAccessTokenEntity fileToken) { var contentType = cc.ContentType?.Id ?? cc.ContentTypeId; if (contentType == ContentTypes.Image) { return(CreateWithImageContent(cc.Id, cc.LaneId, fileToken, cc.DisplayFileName)); } else if (contentType == ContentTypes.PlainText) { return(CreateWithPlainTextContent(cc.Id, cc.LaneId, cc.TextContent)); } else if (contentType == ContentTypes.File) { return(CreateWithFileContent(cc.Id, cc.LaneId, fileToken, cc.DisplayFileName)); } throw new Exception("Unexpected Content Type"); }
public async Task <ActionResult> AssignContent(AssignContentToLanePutData data) { using System.Data.SqlClient.SqlConnection connection = this.authService.Connection; DatabaseContext context = new DatabaseContext(connection); ClipboardContentEntity content = await context.ClipboardContent.FindAsync(data.ContentId); if (content.UserId != this.authService.UserId) { throw new Exception("Content belongs to another user"); } content.LaneId = data.LaneId; await context.SaveChangesAsync(); await connection.CloseAsync(); return(this.Ok()); }
public async Task <ActionResult> DeleteAsync(Guid Id) { using SqlConnection connection = this.authService.Connection; DatabaseContext context = new DatabaseContext(connection); ClipboardContentEntity cc = await context.ClipboardContent.FindAsync(Id); cc.IsArchived = true; if (cc.UserId != this.authService.UserId) { return(this.BadRequest()); } await context.SaveChangesAsync(); await connection.CloseAsync(); return(this.Ok()); }
public async Task <IActionResult> Put(ClipboardPutData data) { using SqlConnection connection = this.authService.Connection; DatabaseContext context = new DatabaseContext(connection); ClipboardContentEntity cc = await context.ClipboardContent.FindAsync(data.Id); if (cc.UserId != this.authService.UserId) { return(this.BadRequest()); } cc.DisplayFileName = data.FileName; cc.TextContent = data.TextContent; cc.LaneId = data.LaneId; await context.SaveChangesAsync(); await connection.CloseAsync(); return(this.Ok()); }
private async Task <ClipboardGetData> PostFileInternal(IFormFile file, string fileExtension, string fileName, Guid?laneId) { using SqlConnection connection = this.authService.Connection; DateTime now = DateTime.Now; string extension = (fileExtension ?? Path.GetExtension(fileName) ?? Path.GetExtension(file.FileName)); string filename = $"clip_{now:yyyyMMdd'_'HHmmss}" + extension; FileAccessTokenEntity token = await this.fileRepository.UploadInternal(filename, file.OpenReadStream(), connection, false); Guid contentType = this.fileRepository.GetContentTypeForExtension(extension).StartsWith("image") ? Constants.ContentTypes.Image : Constants.ContentTypes.File; ClipboardContentEntity entry = new ClipboardContentEntity() { ContentTypeId = contentType, CreationDate = now, LastUsedDate = now, FileTokenId = token.Id, UserId = this.authService.UserId, DisplayFileName = fileName, LaneId = laneId }; using DatabaseContext context = new DatabaseContext(connection); await context.AddAsync(entry); await context.SaveChangesAsync(); await connection.CloseAsync(); connection.Close(); return(contentType == Constants.ContentTypes.Image ? ClipboardGetData.CreateWithImageContent(entry.Id, entry.LaneId, token, fileName) : ClipboardGetData.CreateWithFileContent(entry.Id, entry.LaneId, token, fileName)); }
public async Task <ClipboardGetData> PostPlainText(ClipboardPostPlainTextData data) { using SqlConnection connection = this.authService.Connection; DateTime now = DateTime.Now; ClipboardContentEntity entry = new ClipboardContentEntity() { ContentTypeId = Constants.ContentTypes.PlainText, CreationDate = now, LastUsedDate = now, TextContent = data.Content, UserId = this.authService.UserId, LaneId = data.LaneGuid }; DatabaseContext context = new DatabaseContext(connection); await context.AddAsync(entry); await context.SaveChangesAsync(); await connection.CloseAsync(); return(ClipboardGetData.CreateWithPlainTextContent(entry.Id, entry.LaneId, entry.TextContent)); }