コード例 #1
0
        public IActionResult Index(int id)
        {
            Globals.HasError = null;
            var projects = _backingService.GetUserProjects(id);

            if (!projects.Success)
            {
                return(StatusCode((int)projects.ErrorCode,
                                  projects.ErrorText));
            }

            var projectsToView = projects.Data.Select(p => new ProjectViewModel
            {
                ProjectId      = p.ProjectId,
                Title          = p.Title,
                Description    = p.Description,
                Category       = p.Category,
                MainImageUrl   = p.MainImageUrl,
                DaysToGo       = (p.DueTo - DateTime.Now).Days,
                Backings       = _backingService.GetProjectBackingsCount(p.ProjectId).Data,
                BackingsAmount = _backingService.GetProjectBackingsAmount(p.ProjectId).Data,
                Goal           = p.Goal,
                Progress       = (int)((decimal)_backingService.GetProjectBackingsAmount(p.ProjectId).Data / p.Goal * 100)
            });

            return(View(projectsToView));
        }
コード例 #2
0
        public IActionResult Index()
        {
            Globals.UserId = HttpContext.Session.GetInt32("UserId");
            var trendingProjects = _backingService.TrendingProjects();

            if (!trendingProjects.Success)
            {
                return(StatusCode((int)trendingProjects.ErrorCode,
                                  trendingProjects.ErrorText));
            }
            var trendingProjectsToView = trendingProjects.Data.Select(p => new ProjectViewModel
            {
                UserName       = _projectService.GetOwnerName(p.ProjectId),
                ProjectId      = p.ProjectId,
                Title          = p.Title,
                Description    = p.Description,
                Category       = p.Category,
                MainImageUrl   = p.MainImageUrl,
                DaysToGo       = (p.DueTo - DateTime.Now).Days,
                Backings       = _backingService.GetProjectBackingsCount(p.ProjectId).Data,
                BackingsAmount = _backingService.GetProjectBackingsAmount(p.ProjectId).Data,
                Goal           = p.Goal,
                Progress       = (int)((decimal)_backingService.GetProjectBackingsAmount(p.ProjectId).Data / p.Goal * 100)
            });

            return(View(trendingProjectsToView));
        }
コード例 #3
0
        public IActionResult Details(int id)
        {
            var project = _projectService.GetProjectById(id);

            if (!project.Success)
            {
                return(StatusCode((int)project.ErrorCode,
                                  project.ErrorText));
            }

            var projectToView = new DetailsViewModel
            {
                UserName       = _projectService.GetOwnerName(project.Data.ProjectId),
                ProjectId      = project.Data.ProjectId,
                Title          = project.Data.Title,
                Description    = project.Data.Description,
                Category       = project.Data.Category,
                DaysToGo       = (project.Data.DueTo - DateTime.Now).Days,
                Goal           = project.Data.Goal,
                MainImageUrl   = project.Data.MainImageUrl,
                Medias         = project.Data.Medias,
                Posts          = project.Data.Posts.OrderByDescending(p => p.CreatedAt),
                RewardPackages = project.Data.RewardPackages.OrderBy(p => p.MinAmount),
                IsFirstImage   = true,
                Backings       = _backingService.GetProjectBackingsCount(id).Data,
                BackingsAmount = _backingService.GetProjectBackingsAmount(id).Data,
                Progress       =
                    (int)((decimal)_backingService.GetProjectBackingsAmount(id).Data / project.Data.Goal * 100),
                InterestingProjects = _projectService.GetAllProjects().Data.Where(p => p.ProjectId != id)
                                      .OrderBy(x => Guid.NewGuid()).Take(3)
                                      .Select(p => new InterestingProject
                {
                    ProjectId    = p.ProjectId,
                    Category     = p.Category,
                    DaysToGo     = (p.DueTo - DateTime.Now).Days,
                    MainImageUrl = p.MainImageUrl,
                    Title        = p.Title,
                    UserName     = _projectService.GetOwnerName(p.ProjectId)
                })
            };


            return(View(projectToView));
        }