private async Task<int> SaveFile(UploadResourceModel file) { Resource newResource = new Resource { Name = file.Name, MimeType = file.ContentType, Base64 = file.Base64, Url = file.Base64, DateUploaded = DateTime.Now, }; await SaveToDatabase(newResource).WithoutSync(); return newResource.Id; }
private async Task<int> SaveFile(HttpPostedFileBase file) { string path = SaveToDisk(file); byte[] rawBytes; using (MemoryStream stream = new MemoryStream()) { file.InputStream.CopyTo(stream); rawBytes = stream.ToArray(); } string base64 = Convert.ToBase64String(rawBytes); base64 = $"data:{ file.ContentType.ToLower().Trim() };base64,{ base64 }"; Resource newResource = new Resource { Name = file.FileName, MimeType = file.ContentType, Url = path, Base64 = base64, DateUploaded = DateTime.Now, }; await SaveToDatabase(newResource).WithoutSync(); return newResource.Id; }
private async Task<int> SaveToDatabase(Resource resource) { _resourcesRepository.Insert(resource); await _resourcesRepository.SaveAsync(); int resourceId = resource.Id; resource.Url = ApplicationUrl + resourceId; _resourcesRepository.Update(resource); await _resourcesRepository.SaveAsync(); return resourceId; }