public ActionResult Profile(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } User user = db.User.Find(id); Customer customer = db.Customer.Find(id); if (user == null && !IsACustomer(id)) { return(HttpNotFound()); } var idCard = ((System.Web.HttpContext.Current.User as MyIdentity.MyPrincipal).Identity as MyIdentity).User.IdCard; if (user.IdCard == idCard) { return(RedirectToAction("UserProfile", "Account")); } ProfileModel model = new ProfileModel(); model.IdCard = user.IdCard; model.FirstName = user.FirstName; model.LastName = user.LastName; model.Birth = user.BirthDate.ToString("dd MMMM yyyy"); model.Nationality = db.Country.Find(user.Nationality).Name; model.Username = user.Username; model.MiddleName = user.MiddleName; model.SecondLastName = user.SecondLastName; model.Gender = (user.Gender == "M") ? "Male" : "Female"; ObjectParameter followersQty = new ObjectParameter("Qty", typeof(int)); db.PR_GetFollowersCount(id, followersQty); model.Followers = (int)followersQty.Value; ObjectParameter followingQty = new ObjectParameter("Qty", typeof(int)); db.PR_GetFriendsCount(id, followingQty); model.Following = (int)followingQty.Value; model.Reviews = customer.Review.Count; model.Timeline = customer.Review.OrderByDescending(r => r.Date).ToList(); return(View(model)); }
public ActionResult UserProfile() { var identity = (System.Web.HttpContext.Current.User as MyIdentity.MyPrincipal).Identity as MyIdentity; User loggedUser = db.User.Find(identity.User.IdCard); Customer customer = db.Customer.FirstOrDefault(a => a.IdCard.Equals(identity.User.IdCard)); ProfileEditViewModel model = new ProfileEditViewModel(); model.Activity = "active"; model.Settings = ""; model.Change = ""; ObjectParameter followersQty = new ObjectParameter("Qty", typeof(int)); db.PR_GetFollowersCount(identity.User.IdCard, followersQty); ObjectParameter followingQty = new ObjectParameter("Qty", typeof(int)); db.PR_GetFriendsCount(identity.User.IdCard, followingQty); model.profileData = new ProfileViewModel { Username = loggedUser.Username, IdCard = loggedUser.IdCard, FirstName = loggedUser.FirstName, MiddleName = loggedUser.MiddleName, LastName = loggedUser.LastName, SecondLastName = loggedUser.SecondLastName, Gender = loggedUser.Gender, BirthDate = loggedUser.BirthDate, Nationality = loggedUser.Nationality, AccountNumber = customer.AccountNumber, Followers = (int)followersQty.Value, Following = (int)followingQty.Value, Reviews = customer.Review.Count }; model.Timeline = db.Review.Where(r => r.IdCustomer == identity.User.IdCard).OrderByDescending(review => review.Date).ToList(); ViewBag.Nationality = new SelectList(db.Country, "IdCountry", "Name", loggedUser.Nationality); return(View(model)); }