public UserViewModel GetUserModel(string id, UserProfileViewModel objentity = null, string friendRequestStatus = "", bool isRequestReceived = false) { var user = new UserProfileViewModel(); if (objentity != null) { user = objentity; } else { user = _userServiceAgent.GetUserById(id); } UserViewModel objmodel = new UserViewModel(); if (user != null) { objmodel.IsRequestReceived = isRequestReceived; objmodel.FriendRequestStatus = friendRequestStatus; objmodel.UserId = user.UserId; objmodel.Name = user.FirstName; objmodel.ProfilePicture = GetProfilePicture(user.ImageUrl, user.Gender); objmodel.Gender = user.Gender; objmodel.DOB = user.DOB?.ToShortDateString(); if (user.DOB != null) { objmodel.Age = Convert.ToString(Math.Floor(DateTime.Now.Subtract(Convert.ToDateTime(user.DOB)).TotalDays / 365.0)) + " Years"; } else { objmodel.Age = "NaN"; } objmodel.Bio = user.Bio; } return(objmodel); }
public ActionResult Index(string id) { var myuserId = User.Identity.GetUserId(); if (string.IsNullOrEmpty(id)) { id = myuserId; } var model = _userServiceAgent.GetUserById(id); model.Posts = _postServiceAgent.GetLatestPostByUser(id)?.ToList() ?? new List <PostViewModel>(); model.Following = _userServiceAgent.FollowingList(id, myuserId).Select(x => x.UserInfo).ToList(); model.Followers = _userServiceAgent.FollowersList(id, myuserId).Select(x => x.UserInfo).ToList(); var user = UserManager.FindById(id); if (user != null) { ViewData["username"] = user.UserName; ViewData["userimage"] = string.IsNullOrEmpty(model?.ImageUrl) ? @"\images\DefaultPhoto.png" : model?.ImageUrl; ViewData["firstname"] = string.IsNullOrEmpty(model?.FirstName) ? "FirstName" : model?.FirstName; } return(View(model)); }
public ActionResult Index() { var myuserId = User.Identity.GetUserId(); var model = _userServiceAgent.GetUserById(myuserId); model.Posts = _postServiceAgent.GetLatestPostByUser(myuserId)?.ToList() ?? new List <PostViewModel>(); model.Following = _userServiceAgent.FollowingList(myuserId, myuserId).Select(x => x.UserInfo).ToList(); model.Followers = _userServiceAgent.FollowersList(myuserId, myuserId).Select(x => x.UserInfo).ToList(); return(View(model)); }
public ActionResult EditProfile(UserViewModel model) { var entity = _userServiceAgent.GetUserById(User.Identity.GetUserId()); entity.FirstName = model.Name; entity.Gender = model.Gender; entity.DOB = Convert.ToDateTime(model.DOB); entity.Bio = model.Bio; entity.UpdatedOn = System.DateTime.Now; _userServiceAgent.SaveProfile(entity); return(RedirectToAction("Profile")); }