public ActionResult Edit() { InvestorAuth cred = check_clientRelation(); if (!cred.Valid) { return(Redirect("@/User/Index/")); } manageClient_Sessions(cred); Models.InvestorEditViewModel investorAccount = new Models.InvestorEditViewModel(User.Identity.GetUserId(), cred.Investor_Id); return(View(investorAccount)); }
public ActionResult Edit(Models.InvestorEditViewModel updateModel, HttpPostedFileBase update_Profile_Image) { InvestorAuth cred = check_clientRelation(); if (!cred.Valid) { return(Redirect("@/User/Index/")); } try { // code to process a posted image file. byte[] picture_bytes = null; if (ModelState.IsValid) { if (update_Profile_Image != null) { if (update_Profile_Image.ContentLength > 0) { int MaxContentLength = 1024 * 1024 * 3; string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png", ".pdf" }; if (!AllowedFileExtensions.Contains(update_Profile_Image.FileName.Substring(update_Profile_Image.FileName.LastIndexOf('.')))) { ModelState.AddModelError("profile_picture", "Please only use file types: " + string.Join(", ", AllowedFileExtensions)); } else if (update_Profile_Image.ContentLength > MaxContentLength) { ModelState.AddModelError("profile_picture", string.Format("Your file is too large, maximum file size is: {0} Bytes.", MaxContentLength)); } else { picture_bytes = new byte[update_Profile_Image.ContentLength]; update_Profile_Image.InputStream.Read(picture_bytes, 0, update_Profile_Image.ContentLength); } } } } Models.InvestorEditViewModel authModel = new Models.InvestorEditViewModel(User.Identity.GetUserId(), cred.Investor_Id); authModel.Name = updateModel.Name; authModel.Profile_Public = updateModel.Profile_Public; authModel.Profile_Picture = picture_bytes; authModel.updateInvestor(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); return(View()); } return(Redirect("/User/Index")); }
/// <summary> /// Private method that authenticates whether or not the user and investor are related. /// </summary> /// <returns></returns> private InvestorAuth check_clientRelation() { InvestorAuth cred = new InvestorAuth(); // we have to get the investor id from the url pattern for this page. int investor_id = 0; string[] holding = Request.RawUrl.Split(new char[] { '/' }); try { investor_id = Convert.ToInt32(holding[holding.Count <string>() - 1]); } catch { System.Diagnostics.Debug.WriteLine("No Investor Id parameter was passed in."); } Models.InvestorIndexViewModel authModel = new Models.InvestorIndexViewModel(User.Identity.GetUserId(), investor_id); cred.Valid = authModel.Valid; cred.Investor_Id = investor_id; cred.User_Id = authModel.User_Id; return(cred); }
/// <summary> /// Private method that sets the client's session IDs for what investor account they are presently signes in as. /// </summary> /// <param name="cred"></param> private void manageClient_Sessions(InvestorAuth cred) { int getSession = 0; if (Session["Investor_ID"] != null) { getSession = (int)Session["Investor_ID"]; } if (getSession == 0) { Session.Add("Investor_ID", cred.Investor_Id); } else { if (getSession != cred.Investor_Id) { Session["Investor_ID"] = cred.Investor_Id; } // else it is equal and nothing needs to be done. } }