public ActionResult Index(ProfileViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            this.UpdateUserSettings(this.UserProfile, model);
            if (model.UploadedImage != null)
            {
                using (var memory = new MemoryStream())
                {
                    model.UploadedImage.InputStream.CopyTo(memory);
                    var content = memory.GetBuffer();

                    this.UserProfile.Image = new Image
                    {
                        Content = content,
                        FileExtension = model.UploadedImage.FileName.Split(new[] { '.' }).Last(),
                        CreatedOn = DateTime.Now
                    };
                }
            }

            this.Users.Update();
            return this.RedirectToAction("Index", "Organization", new {area = "Private" });
        }
 public static void CreateModel()
 {
     if (_pModel == null)
     {
         _pModel = new ProfileViewModel();
     }
 }
Example #3
0
        public ActionResult Profile()
        {
            if (this.User.Identity.IsAuthenticated)
            {
                string userId = this.User.Identity.GetUserId();
                var user = this.Data.Users.All()
                    .FirstOrDefault(u => u.Id == userId);

                IQueryable<TweetViewModel> tweets = this.Data.Tweets.All()
                    .Where(t => t.UserId == userId)
                    .Select(TweetViewModel.Create);
                IQueryable<UserViewModel> following = user.Following
                    .AsQueryable()
                    .Select(UserViewModel.Create);
                IQueryable<UserViewModel> followers = user.Followers
                    .AsQueryable()
                    .Select(UserViewModel.Create);
                IQueryable<TweetViewModel> favouriteTweets = user.FavouriteTweets
                    .AsQueryable()
                    .Select(TweetViewModel.Create);
                ProfileViewModel profileViewModel = new ProfileViewModel();

                profileViewModel.Tweets = tweets.ToList();
                profileViewModel.Following = following.ToList();
                profileViewModel.Followers = followers.ToList();
                profileViewModel.FavouriteTweets = favouriteTweets.ToList();

                return View(profileViewModel);
            }
            else
            {
                return RedirectToAction("Login", "Account");
            }
        }
        public async Task<ActionResult> Edit(ProfileViewModel model, HttpPostedFileBase upload)
        {
            var user = _userManager.FindById(User.Identity.GetUserId());
            if (user == null)
            {
                return RedirectToAction("Start", "Main");
            }

            if (upload != null && upload.ContentLength > 0)
            {
                WebImage img = new WebImage(upload.InputStream);
                if (img.Width > 32)
                    img.Resize(32, 32);
                user.Avatar = img.GetBytes();
            }

            user.FirstName = model.FirstName;
            user.LastName = model.LastName;
            user.UserName = model.Username;
            user.Email = model.Email;

            await _userManager.UpdateAsync(user);

            return RedirectToAction("Details", "Profile");
        }
 public Profile()
 {
     InitializeComponent();
     model = new ProfileViewModel();
     this.DataContext = model;
     model.PropertyChanged += model_PropertyChanged;
 }
Example #6
0
        public ActionResult Edit(ProfileViewModel model)
        {
            if (ModelState.IsValid)
            {
                var profile = db.Profiles.Find(model.Profile.ID);
                if (profile == null)
                    return RedirectToAction("Index");

                //update fileds
                profile.FirstName = model.Profile.FirstName;
                profile.LastName = model.Profile.LastName;
                profile.About = model.Profile.About;
                profile.Faculty = model.Profile.Faculty;
                profile.StudyMajor = model.Profile.StudyMajor;
                profile.StudyYear = model.Profile.StudyYear;

                //upload user photo
                try
                {
                    foreach (string upload in Request.Files)
                    {
                        if (Request.Files[upload].ContentLength == 0)
                            continue;

                        string path = AppDomain.CurrentDomain.BaseDirectory + "Content/profile-photos/";

                        FileInfo TheFile = new FileInfo(path + model.Profile.Photo);
                        if (TheFile.Exists)
                        {
                            TheFile.Delete();
                        }

                        string ext = Request.Files[upload].FileName.Substring(Request.Files[upload].FileName.LastIndexOf('.'));
                        profile.Photo = model.Profile.UserName + ext;
                        Request.Files[upload].SaveAs(Path.Combine(path, profile.Photo));
                    }
                }
                catch (NullReferenceException)
                {
                    //no photo
                }
                //end of upload user photo

                try
                {
                    var cats = db.NewsCategories.Where(r => model.CategoryIDs.Contains(r.ID));
                    profile.Subscriptions.Clear();
                    foreach (var cat in cats)
                    {
                        profile.Subscriptions.Add(cat);
                    }
                }
                catch (NotSupportedException) { /* 0 categories */ }

                UpdateModel(profile);
                db.SaveChanges();
                return RedirectToAction("Details", new { id = model.Profile.ID });
            }
            return View(model);
        }
 private void UpdateUserSettings(User model, ProfileViewModel viewModel)
 {
     model.UserName = viewModel.Email;
     model.FirstName = viewModel.FirstName;
     model.LastName = viewModel.LastName;
     model.Email = viewModel.Email;
     model.Position = viewModel.Position;
 }
 public ActionResult Edit(ProfileViewModel model)
 {
     if (ModelState.IsValid)
     {
         Db.Create(model);
     }
     return View(model);
 }
Example #9
0
        public MemberViewModel(Member member, IList<Role> roles)
        {
            this._member = member;
            this._roles = roles;
            this._profile = new ProfileViewModel(member.Profile);

            this._id = member.Id;
            this._password = member.Password;
            this._username = member.Username;
        }
Example #10
0
        public void EditPostTest()
        {
            // Act
            ProfileViewModel profilevm = new ProfileViewModel { Profile = new Profile { ID = 1, UserName = "jj09", LastName = "Doe" } };
            controller.db.Profiles.Add(profilevm.Profile);
            profilevm.Profile.LastName = "Smith";
            RedirectToRouteResult result = controller.Edit(profilevm) as RedirectToRouteResult;

            // Assert
            Assert.AreEqual("Details", result.RouteValues["action"]);
            Assert.AreEqual(profilevm.Profile.LastName, controller.db.Profiles.Find(1).LastName);
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			viewModel = App.ProfileViewModel;
			SetUpNickNameControls ();
			SetUpCollectionView ();
			SetUpAvatarControl ();

			spaceCalculator = new CollectionViewSpaceCalculator (CollectionView, AvatarCollectionViewCell.CellSize);
			gestureAttacher = new LongPressGestureAttacher (AvatarImg, TakeAvatar);
		}
        public ActionResult Index(string searchString)
        {
            var profile = this.profiles.GetAll().To<DetailsProfileViewModel>().ToList();

            if (!String.IsNullOrEmpty(searchString))
            {
                profile = profile.Where(s => s.FullName.ToLower().Contains(searchString.ToLower())).ToList();
            }

            var viewModel = new ProfileViewModel
            {
                Profiles = profile
            };
            return this.View(viewModel);
        }
        public ActionResult Edit()
        {
            var user = _userManager.FindById(User.Identity.GetUserId());
            if (user == null)
            {
                return RedirectToAction("Start", "Main");
            }

            var model = new ProfileViewModel()
            {
                Username = user.UserName,
                Email = user.Email,
                FirstName = user.FirstName,
                LastName = user.LastName
            };

            return View(model);
        }
Example #14
0
        public ActionResult AtAGlance()
        {
            string name = User.Identity.Name;
            ApplicationUser user = db.Users.Single(x => x.UserName == name);
            ProfileViewModel vm = new ProfileViewModel
            {
                FirstName = user.FirstName,
                LastName = user.LastName,
                Email = user.Email,
                UserName = user.UserName,
            };

            //pass all user households to view
            vm.Households = user.Households;

            string profilePicUrl = user.ProfilePicUrl;
            vm.ProfilePicUrl = profilePicUrl;

            return View(vm);
        }
        public ActionResult Index(ProfileViewModel profileInfo)
        {
            //if (ModelState.IsValid)
            //{
                using (InternetStoreDBContext dbc = new InternetStoreDBContext())
                {
                    var newUserInfo = new Classes.User();
                    var oldUserInfo = (from u in dbc.Users where u.Email == profileInfo.Email select u).ToList().FirstOrDefault();
                    if (oldUserInfo != null)
                    {
                        dbc.Users.DeleteOnSubmit(oldUserInfo);
                        dbc.SubmitChanges();

                        //Currently constant fields:
                        newUserInfo.ID = oldUserInfo.ID;
                        newUserInfo.UserName = oldUserInfo.UserName;
                        newUserInfo.Password = oldUserInfo.Password;
                        //Changable fields:
                        newUserInfo.FirstName = profileInfo.FirstName;
                        newUserInfo.LastName = profileInfo.LastName;
                        newUserInfo.Phone = profileInfo.Phone;
                        newUserInfo.Address = profileInfo.Address;
                        newUserInfo.Email = profileInfo.Email;

                        dbc.Users.InsertOnSubmit(newUserInfo);
                        dbc.SubmitChanges();

                        ProfileViewModel newProfile = new ProfileViewModel();
                        newProfile.UserName = newUserInfo.UserName ?? "";
                        newProfile.FirstName = newUserInfo.FirstName ?? "";
                        newProfile.LastName = newUserInfo.LastName ?? "";
                        newProfile.Email = newUserInfo.Email ?? "";
                        newProfile.Phone = newUserInfo.Phone ?? "";
                        newProfile.Address = newUserInfo.Address ?? "";

                        return View(newProfile);
                    }
                }
            //}
            return View(profileInfo);
        }
        public void ShouldBeAbleToCallSaveProfileMethod()
        {
            // arrange
            var controller = new ProfileController(this.MembershipService, this.FormsAuthentication);
            var profileView = new ProfileViewModel
                {
                    FirstName = "Vitali",
                    LastName = "Hatalski",
                    NotifyOnOrderStatusChanged = true,
                    NotifyOnPackageStatusChanged = true
                };

            // act
            var actual = ((JsonNetResult)controller.Save(profileView)).Data as ProfileViewModel;

            // assert
            Assert.That(actual, Is.Not.Null);
            if (actual != null)
            {
                Assert.That(actual.MessageType, Is.EqualTo(MessageType.Success.ToString()));
            }
        }
Example #17
0
        public ActionResult Save(ProfileViewModel model)
        {
            var result = new ProfileViewModel();
            var validator = new ProfileViewModelValidator();
            var validationResult = validator.Validate(model);

            if (validationResult.IsValid)
            {
                var request = model.ConvertToUpdateProfileRequest();
                request.IdentityToken = this.FormsAuthentication.GetAuthenticationToken();
                var response = this.membershipService.UpdateProfile(request);
                result = response.ConvertToProfileViewModel();
                result.Message = response.Message;
            }
            else
            {
                result.MessageType = MessageType.Warning.ToString();
                result.Message = CommonResources.ProfileUpdateErrorMessage;
                result.FirstName = model.FirstName;
                result.LastName = model.LastName;
                result.NotifyOnOrderStatusChanged = model.NotifyOnOrderStatusChanged;
                result.NotifyOnPackageStatusChanged = model.NotifyOnPackageStatusChanged;
                result.BrokenRules = new List<BusinessRule>();
                foreach (var failure in validationResult.Errors)
                {
                    result.BrokenRules.Add(new BusinessRule(failure.PropertyName, failure.CustomState.ToString()));
                }
            }

            result.Email = this.FormsAuthentication.GetAuthenticationToken();

            var jsonNetResult = new JsonNetResult
            {
                Formatting = (Formatting)Newtonsoft.Json.Formatting.Indented,
                Data = result
            };
            return jsonNetResult;
        }
        public ActionResult Settings(ProfileViewModel profile)
        {
            if (profile == null)
                return null;

            var user = GetUser();

            if (user == null)
                RedirectToAction("Index", "Home");

            profile.Id = user.Id;

            bool success = _profileService.Update(EntityConvert<ProfileViewModel, UserProfileBLL>(profile));

            if (success)
            {
                ViewBag.Success = true;
                return View(profile);
            }

            ViewBag.NotSuccess = true;
            return View(profile);
        }
        public ActionResult Index(string returnUrl)
        {
            ProfileViewModel profile = new ProfileViewModel();

            if (User.Identity.IsAuthenticated)
            {
                using (InternetStoreDBContext dbc = new InternetStoreDBContext())
                {
                    var currentUser = (from u in dbc.Users where u.Email == User.Identity.Name select u).ToList().FirstOrDefault();
                    if (currentUser != null)
                    {
                        profile.UserName = currentUser.UserName ?? "";
                        profile.FirstName = currentUser.FirstName ?? "";
                        profile.LastName = currentUser.LastName ?? "";
                        profile.Email = currentUser.Email ?? "";
                        profile.Phone = currentUser.Phone ?? "";
                        profile.Address = currentUser.Address ?? "";
                    }
                }
            }
            ViewBag.ReturnUrl = returnUrl;
            return View(profile);
        }
        public JsonResult GetUserProfile(string key, string username)
        {
            if (apiServices.IsValidKey(key))
            {
                UserProfileModel upm = accountServices.GetUserProfileByUsername(username);
                ProfileViewModel pvm = new ProfileViewModel();
                pvm.FirstName = upm.FirstName;
                pvm.LastName = upm.LastName;
                pvm.Description = upm.Description;
                pvm.Reputation = upm.Reputation;
                pvm.Birthdate = upm.Birthdate;
                pvm.GenderText = upm.IsFemale ? "Female" : "Male";

                apiServices.IncrementKeyUsage(key);

                return Json(pvm, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(null, JsonRequestBehavior.AllowGet);
            }
        }
Example #21
0
 /// <summary>
 /// Gets the profile details.
 /// </summary>
 /// <param name="id">User profile ID.</param>
 /// <returns>Profile view model.</returns>
 private ProfileViewModel GetProfile(long id)
 {
     var profileDetails = ProfileService.GetProfile(id);
     var userDetail = new ProfileViewModel();
     if (profileDetails != null)
     {
         Mapper.Map(profileDetails, userDetail);
         userDetail.IsCurrentUser = CurrentUserId == profileDetails.ID;
         userDetail.ProfileName = profileDetails.GetProfileName();
         userDetail.ProfilePhotoLink = string.IsNullOrWhiteSpace(userDetail.ProfilePhotoLink) ? "~/Content/Images/profile.png" : Url.Action("Thumbnail", "File", new { id = userDetail.ProfilePhotoLink });
     }
     return userDetail;
 }
 public ActionResult ViewEdit(ProfileViewModel model)
 {
     return View(model);
 }
 public NotificationsListViewModel(Dictionary<IEventEntity, bool> dictionaryEntitiesSeen, ProfileViewModel profile)
 {
     NotificationEntities = dictionaryEntitiesSeen.Keys.ToList();
     SeenDictionary = dictionaryEntitiesSeen;
     Profile = profile;
 }
Example #24
0
 public ActionResult My(ProfileViewModel model)
 {
     Edit(model);
     return RedirectToAction("Details", new { id = model.Profile.ID });
 }
Example #25
0
        public ServiceOperationResult UpdateProfile(ProfileViewModel model)
        {
            User oldUser = UserRepository.GetUser(model.Id);
            User newUser = Mapper.Map<ProfileViewModel, User>(model);

            return Mapper.Map<DataResult, ServiceOperationResult>(UserRepository.UpdateProfile(oldUser, newUser));
        }
Example #26
0
        //// GET: /Account/Manage/Index
        public ActionResult Index(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.ChangeEmailSuccess ? "Your email has been changed."
                : message == ManageMessageId.Error ? "An error has occurred."
                : string.Empty;

            var user = this.UserManager.FindById(User.Identity.GetUserId());

            var model = new ProfileViewModel
            {
                UserName = user.UserName,
                Email = user.Email,
                CreateOn = user.CreatedOn
            };

            return this.View(model);
        }
        public JsonResult GetFriends(string key, string username)
        {
            if (apiServices.IsValidKey(key))
            {
                UserProfileModel userProfile = accountServices.GetUserProfileByUsername(username);
                GetFriendsModel gfm = new GetFriendsModel();
                gfm.UserProfileId = userProfile.UserProfileId;
                List<UserProfileModel> friends = accountServices.GetAllFriends(gfm).ToList();

                ProfileViewModel[] result = new ProfileViewModel[friends.Count];
                ProfileViewModel pvm;

                for (int i = 0; i < friends.Count; i++)
                {
                    pvm = new ProfileViewModel();
                    pvm.FirstName = friends[i].FirstName;
                    pvm.LastName = friends[i].LastName;
                    pvm.Description = friends[i].Description;
                    pvm.Reputation = friends[i].Reputation;
                    pvm.Birthdate = friends[i].Birthdate;
                    pvm.GenderText = friends[i].IsFemale ? "Female" : "Male";

                    result[i] = pvm;
                }

                apiServices.IncrementKeyUsage(key);

                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(null, JsonRequestBehavior.AllowGet);
            }
        }
        public void ShouldNotBeAbleToSaveInvalidProfileView()
        {
            // arrange
            var controller = new ProfileController(this.MembershipService, this.FormsAuthentication);
            controller.ViewData.ModelState.Clear();

            var profileViewModel = new ProfileViewModel
            {
                FirstName = "Vitali",
                LastName = string.Empty,
                NotifyOnOrderStatusChanged = true,
                NotifyOnPackageStatusChanged = true
            };

            // act
            var actual = controller.Save(profileViewModel) as JsonNetResult;

            // assert
            Assert.That(actual, Is.Not.Null);
            if (actual != null)
            {
                var model = actual.Data as ProfileViewModel;
                Debug.Assert(model != null, "model != null");
                Assert.That(model.MessageType, Is.EqualTo(MessageType.Warning.ToString()));
            }
        }
        private ProfileViewModel GetProfileViewModel(string username)
        {
            UserProfileModel profile = accountServices.GetUserProfileByUsername(username);
            if (profile == null) return null;

            ProfileViewModel model = new ProfileViewModel
            {
                AvatarUrl = profile.Avatar,
                Birthdate = profile.Birthdate,
                Description = profile.Description,
                FirstName = profile.FirstName,
                GenderText = profile.IsFemale ? "Female" : "Male",
                LastName = profile.LastName,
                Reputation = profile.Reputation,
                UserProfileId = profile.UserProfileId
            };

            model.Friends = accountServices.GetFriendsList(profile.UserProfileId, NUM_FRIENDS);
            model.UserEvents = EventServices.GetInstance().GetAllEventsByUserProfileId(profile.UserProfileId).Take(NUM_EVENTS);
            UserModel temp = accountServices.GetUserByUsername(username);
            model.Username = username;
            model.UserId = temp.UserId;

            model.ViewingFriend = accountServices.AreFriends(User.Identity.Name, username);
            model.ViewingOwn = User.Identity.Name == username;

            int numFriends = accountServices.GetAllFriends(new GetFriendsModel { UserProfileId = profile.UserProfileId }).Count();

            model.Sidebar = new ProfileSidebarViewModel { AvatarUrl = profile.Avatar, FriendCount = numFriends, Name = profile.FirstName + " " + profile.LastName, Reputation = profile.Reputation, Username = username };

            model.ThisDudeHasSentAFriendRequestToYou = (User.Identity.Name == "") ? false : accountServices.HasPendingFriendRequest(username, User.Identity.Name);
            model.FriendRequested = (User.Identity.Name == "") ? false : accountServices.HasPendingFriendRequest(User.Identity.Name, username);
            return model;
        }
 public ActionResult Index(int id) {
     var profile = new ProfileViewModel();
     return View(profile);
 }