Пример #1
0
        // GET: UserManager/Create
        public ActionResult Create()
        {
            var rolesList = new List <Models.RoleViewModel>();
            var mdl       = new Models.UserEditViewModel();

            db.Roles.ForEachAsync(item =>
            {
                rolesList.Add(new RoleViewModel {
                    Id = item.Id, Name = item.Name
                });
            });
            mdl.RolesList = rolesList;
            return(View(mdl));
        }
        public ActionResult Edit(Models.UserEditViewModel updateModel, HttpPostedFileBase update_Profile_Image)
        {
            // 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);
                        }
                    }
                }
            }

            // code to update user account
            Models.UserEditViewModel user_to_update = new Models.UserEditViewModel(User.Identity.GetUserId());
            Models.UserEditViewModel updateUser     = new Models.UserEditViewModel()
            {
                User_Email = updateModel.User_Email, User_Image = picture_bytes, Image_Id = user_to_update.Image_Id
            };
            updateUser.updateUser(user_to_update.User_Id);
            return(Redirect("/User/Index"));
        }
 public ActionResult Edit()
 {
     Models.UserEditViewModel userAccount = new Models.UserEditViewModel(User.Identity.GetUserId());
     return(View(userAccount));
 }