public ActionResult DeletePhoto(int userId)
        {
            Private(userId, true);

            if (ModelIsValid)
            {
                var user = Execute(() => _accountService.GetUser(userId));
                var path = string.Concat(AppDomain.CurrentDomain.BaseDirectory, user.PhotoPath);

                Execute(() => _accountService.DeleteUserPhoto(userId));

                if (CurrentUser.IsMe(userId))
                    Execute(() => CurrentUser = _accountService.GetUser(userId));

                if (ModelIsValid && System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                    return RedirectToAction<AccountProfileController>(o => o.ProfileInfo(userId));
                }
            }

            var model = new UserProfileModel { UserId = userId };
            FillUserProfileModel(model);
            return View("ProfileInfo", model);
        }
        public ActionResult ProfileInfo(int userId)
        {
            var model = new UserProfileModel { UserId = userId };
            FillUserProfileModel(model);

            if (ModelIsValid)
                return View(model);
            return RedirectToAction<HomeController>(o => o.Index());
        }
 private void FillUserProfileModel(UserProfileModel model)
 {
     var userProfile = Execute(() => _accountService.GetUserProfile(model.UserId));
     model.CopyFrom(userProfile);
 }
        public ActionResult EditPhoto(int userId, HttpPostedFileBase photoUploadFile)
        {
            Private(userId, true);

            if (ModelIsValid)
            {
                if (photoUploadFile != null && photoUploadFile.FileName != null)
                {
                    try
                    {
                        if (photoUploadFile.ContentLength > 102400)
                            ModelState.AddModelError(string.Empty, "Размер файла не выше 100кб");

                        if (!Constants.AcceptImage.Contains(photoUploadFile.ContentType))
                            ModelState.AddModelError(string.Empty, "Требуемые форматы: *.jpg, *.jpeg, *.png, *.gif");

                        if (ModelIsValid)
                        {
                            var image = Image.FromStream(photoUploadFile.InputStream);
                            if (image.Width > 200 || image.Height > 200)
                                ModelState.AddModelError(string.Empty, "Разрешение фото не должно превышать 200х200");
                        }

                        if (ModelIsValid)
                        {
                            var user = Execute(() => _accountService.GetUser(userId));
                            var oldPath = string.Concat(AppDomain.CurrentDomain.BaseDirectory, user.PhotoPath);

                            var fileName = string.Concat(StringGeneration.Generate(20), Path.GetExtension(photoUploadFile.FileName));
                            var path = Path.Combine(Server.MapPath(Constants.PhotoDirectoryPath), Path.GetFileName(fileName));
                            while (System.IO.File.Exists(path))
                                fileName = string.Concat(StringGeneration.Generate(20), Path.GetExtension(photoUploadFile.FileName));

                            photoUploadFile.SaveAs(path);

                            Execute(() => _accountService.UpdateUserPhoto(userId, string.Concat(Constants.PhotoDirectoryPath, fileName)));

                            if (CurrentUser.IsMe(userId))
                                Execute(() => CurrentUser = _accountService.GetUser(userId));

                            if (ModelIsValid)
                            {
                                if (System.IO.File.Exists(oldPath))
                                    System.IO.File.Delete(oldPath);

                                return RedirectToAction<AccountProfileController>(o => o.ProfileInfo(userId));
                            }
                        }
                    }
                    catch (Exception)
                    {
                        ModelState.AddModelError(string.Empty, "Ошибка при сохранении файла");
                    }
                }
                else
                    ModelState.AddModelError(string.Empty, "Файл не выбран");
            }

            var model = new UserProfileModel { UserId = userId };
            FillUserProfileModel(model);
            return View("ProfileInfo", model);
        }