public FileModel ConvertToModel(File file) { FileModel fileM = new FileModel() { FileName = file.FileName, Content = file.Content, ContentType = file.ContentType, FileType = (FileType)file.FileType, }; return fileM; }
public async Task<ActionResult> Edit([Bind(Include = "UserId,ProfileId,FirstName,LastName,Age,Country,City,School,Degree,About")] Profile profile, HttpPostedFileBase upload) { File avatar; if (upload != null && upload.ContentLength > 0) { avatar = new File(); avatar.FileName = System.IO.Path.GetFileName(upload.FileName); avatar.FileType = (short)FileType.Picture; avatar.ContentType = upload.ContentType; using (var reader = new System.IO.BinaryReader(upload.InputStream)) { avatar.Content = reader.ReadBytes(upload.ContentLength); } profile.Files = new List<File> { avatar }; } else avatar = null; using (HttpClient httpClient = new HttpClient()) { var result = await httpClient.PutAsJsonAsync<Profile>(baseUri, profile); if (result.IsSuccessStatusCode) { return RedirectToAction("Index"); } else { return View("Error"); } } }