Пример #1
0
        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));
        }
Пример #2
0
        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"));
        }