public JsonResult UploadFile() { if (Request.Files.Count.Equals(0)) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Result = "Error" })); } try { var buApplicationUser = new BuApplicationUser(); var user = buApplicationUser.GetByUserName(User.Identity.GetUserName()); for (var i = 0; i < Request.Files.Count; i++) { var poImgFile = Request.Files[i]; using (var binary = new BinaryReader(poImgFile.InputStream)) user.ProfilePhoto = binary.ReadBytes(poImgFile.ContentLength); } buApplicationUser.Update(user); return(Json(new { Result = "Ok" })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public ActionResult Index() { if (!User.Identity.IsAuthenticated) { return(View()); } var buApplicationUser = new BuApplicationUser(); var user = buApplicationUser.GetByUserName(User.Identity.GetUserName()); return(View(user)); }
public FileContentResult ProfilePhoto() { if (!User.Identity.IsAuthenticated || string.IsNullOrEmpty(User.Identity.GetUserId())) { return(File(LoadDefaultProfilePhoto(), "image/png")); } var buApplicationUser = new BuApplicationUser(); var user = buApplicationUser.GetByUserName(User.Identity.GetUserName()); return(user?.ProfilePhoto == null?File(LoadDefaultProfilePhoto(), "image/png") : new FileContentResult(user.ProfilePhoto, "image/jpeg")); }
public JsonResult DeleteFile() { try { var buApplicationUser = new BuApplicationUser(); var user = buApplicationUser.GetByUserName(User.Identity.GetUserName()); user.ProfilePhoto = null; buApplicationUser.Update(user); return(Json(new { Result = "Ok" })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }