public async Task <ActionResult> SetProfilePicture([Bind(Exclude = "ProfilePicture")] ChangeProfilePictureModel model) { try { if (ModelState.IsValid) { byte[] imageData = null; if (Request.Files.Count > 0) { //TODO: Bilden kommer inte fram. Den blir null HttpPostedFileBase poImgFile = Request.Files["ProfilePicture"]; using (var binary = new BinaryReader(poImgFile.InputStream)) { imageData = binary.ReadBytes(poImgFile.ContentLength); } } //Spara inloggand användare var user = UserManager.FindById(User.Identity.GetUserId()); //Ändra användarens nickname & spara ändringen i databasen user.ProfilePicture = imageData; IdentityResult result = await UserManager.UpdateAsync(user); } return(RedirectToAction("MyPage", "User")); } catch { ViewBag.FelStorlek = "För stor bild."; return(RedirectToAction("ChangeProfilePicture", new { Message = "Du måste välja en bild." })); } }
// GET: /Manage/ChangeNickname public ActionResult ChangeProfilePicture(ChangeProfilePictureModel model) { return(View(model)); }