Exemple #1
0
        public ActionResult Details(string id)
        {
            var user = regularUserService.GetById(id);

            if (user != null)
            {
                IEnumerable <ProjectCreateViewModel> projects = null;
                if (user.Projects != null && user.Projects.Count > 0)
                {
                    projects = user.Projects.Select(
                        p => new ProjectCreateViewModel()
                    {
                        Id    = p.Id,
                        Title = p.Title
                    });
                }

                IEnumerable <StoryCreateViewModel> stories = null;
                if (user.Stories != null && user.Stories.Count > 0)
                {
                    stories = user.Stories.Select(
                        s => new StoryCreateViewModel()
                    {
                        Id    = s.Id,
                        Title = s.Title
                    });
                }

                var viewModel = new ProfileDetailsViewModel()
                {
                    CarManiacForDays = (int)(DateTime.Now - user.RegisterDate).TotalDays,
                    AvatarUrl        = user.AvatarUrl,
                    FirstName        = user.FirstName,
                    LastName         = user.LastName,
                    Age                 = user.Age,
                    CurrentCar          = user.CurrentCar,
                    FavoriteCar         = user.FavoriteCar,
                    Projects            = projects,
                    Stories             = stories,
                    IsUserAllowedToEdit = this.User.Identity.GetUserId() == user.Id
                };
                return(View(viewModel));
            }

            return(new HttpNotFoundResult());
        }
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (this.Request.HttpMethod == "GET" && this.User.Identity.IsAuthenticated)
            {
                if (this.HttpContext.Session["AvatarUrl"] == null)
                {
                    IRegularUserService regularUserService = DependencyResolver.Current.GetService(typeof(IRegularUserService)) as IRegularUserService;
                    Guard.WhenArgument(regularUserService, "regularUserService").IsNull().Throw();

                    string avatarUrl = regularUserService.GetById(this.User.Identity.GetUserId()).AvatarUrl;
                    this.HttpContext.Session["AvatarUrl"] = avatarUrl;
                    this.ViewBag.AvatarUrl = avatarUrl;
                }
                else
                {
                    this.ViewBag.AvatarUrl = this.HttpContext.Session["AvatarUrl"].ToString();
                }
            }

            base.OnActionExecuting(filterContext);
        }