// Executes DELETE requsts
        private async Task <ActionResult> DeleteHandler(IFileHandler handler)
        {
            // Get the file to delete
            handler.FileStatus = handler.Services.DELETE.GetRequestStatus();
            IFileStatusItem file = handler.FileStatus.Files[0];

            using (FilesModel db = new FilesModel())
            {
                Guid id = Guid.Parse(file.FileName);

                File f = db.Files.Find(id);
                db.Files.Remove(f);
                await db.SaveChangesAsync();
            }

            // Create client plugin specific result and return an ActionResult
            IBackloadResult result = handler.Services.Core.CreatePluginResult();

            return(ResultCreator.Create((IFileStatusResult)result));
        }
        // Executes POST requsts
        private async Task <ActionResult> PostHandler(IFileHandler handler)
        {
            // Get the posted file with meta data from the request
            handler.FileStatus = await handler.Services.POST.GetPostedFiles();

            if (handler.FileStatus != null)
            {
                Guid            id   = Guid.NewGuid();
                IFileStatusItem file = handler.FileStatus.Files[0];


                // Read the file data (bytes)
                byte[] data = null;
                using (System.IO.MemoryStream stream = new System.IO.MemoryStream((int)file.FileSize))
                {
                    await file.FileStream.CopyToAsync(stream);

                    data = stream.ToArray();
                }


                // Create the thumbnail
                await handler.Services.POST.CreateThumbnail(file);

                // Create a base64 encoded data url for the thumbnail we can return in Json
                await handler.Services.Core.CreateThumbnailDataUrls();


                // This will change the url query parameter fileName to the id of the
                // new table row, so we can identify the file in a DELETE and GET request
                file.FileUrl   = file.DeleteUrl.Replace(file.FileName, id.ToString());
                file.DeleteUrl = file.FileUrl;


                // Store to db
                using (FilesModel db = new FilesModel())
                {
                    // File entity represents a table row
                    File row = new File()
                    {
                        Id         = id,
                        Data       = data,
                        Name       = file.FileName,
                        Original   = file.OriginalName,
                        Size       = file.FileSize,
                        Type       = file.ContentType,
                        UploadTime = DateTime.Now,
                        Preview    = file.ThumbnailUrl
                    };

                    File f = db.Files.Add(row);
                    await db.SaveChangesAsync();
                };
            }


            // Create client plugin specific result and return an ActionResult
            IBackloadResult result = handler.Services.Core.CreatePluginResult();

            return(ResultCreator.Create((IFileStatusResult)result));
        }