public ActionResult AvatarUpload(HttpPostedFileBase file) { Account account = GetAccount(); Profile profile = profileDAL.fetchByAccountID(account.accountID); if (file != null) { byte[] uploadedImage = new byte[file.InputStream.Length]; string pic = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/content/images/avatars"), pic); string extension = Path.GetExtension(file.FileName).ToLower(); //ensures that only the correct file format is uploaded if (extension == ".png") { file.SaveAs(path); } else if (extension == ".jpg") { file.SaveAs(path); } else if (extension == ".gif") { file.SaveAs(path); } // file is uploaded else { TempData["errorMessage"] = "We only accept .png, .jpg, and .gif!"; return(RedirectToAction("AvatarUpload")); } // save the image path path to the database or you can send image // directly to database // in-case if you want to store byte[] ie. for DB if (file.ContentLength / 1000 < 1000) { using (MemoryStream ms = new MemoryStream()) { file.InputStream.Read(uploadedImage, 0, uploadedImage.Length); profile.profilePic = uploadedImage; } } else { TempData["errorMessage"] = @"The file you uploaded exceeds the size limit. Please reduce the size of your file and try again."; } } profileDAL.Update(profile); return(RedirectToAction("AvatarImage")); }
public ActionResult AcceptProfile(int id = 0) { Account account = accountDAL.FetchByID(id); if (account == null) { TempData["errorMessage"] = "Sorry. This user does not exist !"; return(RedirectToAction("AdminDashboard")); } else { account.Profile.isApproved = true; _email.SendProfileApprovedEmail(account.email, account.email); profileDAL.Update(account.Profile); TempData["successMessage"] = "Profile has been approved"; } return(RedirectToAction("AdminDashboard")); }