Exemplo n.º 1
0
 public ProfileViewModel ToProfileViewModelFromUser(User user)
 {
     var profileViewModel = new ProfileViewModel
         {
             UserName = user.UserName,
             Email = user.Email,
             Password = user.Password,
             Gender = user.Gender,
             ImageName = string.IsNullOrEmpty(user.ImageUrl) ? string.Empty : user.ImageUrl,
             Introduction = user.Introduction
         };
     return profileViewModel;
 }
Exemplo n.º 2
0
        public ActionResult Profiles()
        {
            try
            {

                var userId = _cookieHelper.GetUserId(Request);
                var user = _userLogic.Get(userId);
                var webPath = string.Format("{0}{1}.jpg", UserConfig.UserImageUrl, userId);
                var ioPath = Server.MapPath(webPath);
                var imageUrl = System.IO.File.Exists(ioPath) ? webPath : string.Empty;
                var profileViewModel = new ProfileViewModel
                {
                    UserName = user.UserName,
                    Email = user.Email,
                    Password = user.Password,
                    RepeatPassword = user.Password,
                    Gender = user.Gender,
                    Introduction = user.Introduction,
                    CurrentUserName = user.UserName,
                    ImageUrl = imageUrl
                };
                return View(profileViewModel);
            }
            catch (Exception)
            {
                return View("Error");
            }
        }
Exemplo n.º 3
0
 public User ToUserFromProfileViewModel(ProfileViewModel profileViewModel)
 {
     var user = new User()
         {
             UserName = profileViewModel.UserName,
             Password = profileViewModel.Password,
             Email = profileViewModel.Email,
             Gender = profileViewModel.Gender,
             ImageUrl = profileViewModel.ImageName,
             Introduction = profileViewModel.Introduction
         };
     return user;
 }
Exemplo n.º 4
0
        public ActionResult Profiles(ProfileViewModel profileViewModel)
        {
            try
            {
                var user = new User
                {
                    UserName = profileViewModel.UserName,
                    Email = profileViewModel.Email,
                    Password = profileViewModel.Password,
                    Gender = profileViewModel.Gender,
                    Introduction = profileViewModel.Introduction,
                    UserId = _cookieHelper.GetUserId(Request),
                };
                _userLogic.Update(user);

                if (profileViewModel.IsUpdateUserImage)
                {
                    var ioPath = Server.MapPath(UserConfig.UserImageUrl);
                    var imgPath = ioPath + user.UserId + ".jpg";
                    var tempImgPath = ioPath + user.UserId + "_temp.jpg";
                    System.IO.File.Delete(imgPath);
                    System.IO.File.Move(tempImgPath, imgPath);
                }

                return new RedirectResult(Url.Action("Index", "Project"));
            }
            catch (Exception)
            {
                return View("Error");
            }
        }