コード例 #1
0
        // GET: /JobOpportunity/Detail/4
        public ActionResult Detail(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("Index"));
            }

            var vm = _jobOpportunityService.GetJobOpportunityById(id);

            if (vm != null)
            {
                ViewBag.RelatedJobs =
                    _jobOpportunityService.GetCompanyRelatedJobs(id.Value, vm.CompanyName, vm.CompanyEmail, vm.CompanyUrl);

                var cookieView = $"JobView{vm.Id}";
                if (!CookieHelper.Exists(cookieView))
                {
                    _jobOpportunityService.UpdateViewCount(vm.Id);
                    CookieHelper.Set(cookieView, vm.Id.ToString());
                }

                return(View("Detail", vm));
            }

            ViewBag.ErrorMessage =
                "La vacante solicitada no existe. Por favor escoger una vacante válida del listado";

            return(View("Index"));
        }
コード例 #2
0
        public void Exists_CookieDoesNotExist_ReturnsFalse()
        {
            // Act
            var exists = CookieHelper.Exists("myKey");

            // Assert
            exists.Should().BeFalse();
        }
コード例 #3
0
        public ActionResult Portfolio(int?Id)
        {
            if (!Id.HasValue)
            {
                return(HomePage());
            }

            var portfolio = portfolioService.GetById(Id.Value);

            if (portfolio == null)
            {
                return(NotFound());
            }

            if (!portfolio.IsActive || portfolio.IsDelete)
            {
                return(NotActive());
            }

            string cookieKey = string.Format(CookieConstant.PORTFOLIO_VIEW, portfolio.Id);

            if (!CookieHelper.Exists(cookieKey))
            {
                CookieHelper.Set(cookieKey, WebHelper.IpAddress, 1);
                portfolio.ViewCount += 1;
                portfolioService.Update(portfolio);
            }

            var model = new PortfolioDetailModel
            {
                Id           = portfolio.Id,
                Title        = portfolio.Title,
                Content      = portfolio.Description,
                PicturePath  = mediaStorageService.GetPictureUrl(portfolio.PictureId),
                Url          = urlService.GetUrl(portfolio.Id, nameof(Portfolio)),
                User         = portfolio.User,
                CreateDate   = portfolio.CreateDateUtc,
                UpdateDate   = portfolio.UpdateDateUtc,
                ViewCount    = portfolio.ViewCount,
                CategoryName = portfolio.Category.Name,
                CategoryUrl  = portfolio.Category.Url,
                Pictures     = portfolio.Pictures
            };

            model.RelatedPortfolios = portfolioService.GetRelatedPortfolios(portfolio.CategoryId, portfolio.Id)
                                      .Select(x => new PortfolioModel
            {
                Id = x.Id,
            }).ToList();

            return(View(this.GetViewName(portfolio), model));
        }
コード例 #4
0
        // GET: /jobs/4-jobtitle
        public ActionResult Detail(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(RedirectToAction(nameof(Index)));
            }

            var jobOpportunityId = GetIdFromTitle(id);

            if (jobOpportunityId == 0)
            {
                return(RedirectToAction(nameof(Index)));
            }

            var jobOpportunity = _jobOpportunityService.GetJobOpportunityById(jobOpportunityId);

            if (jobOpportunity == null)
            {
                return(View(nameof(Index))
                       .WithError("La vacante solicitada no existe. Por favor escoge una vacante válida del listado"));
            }

            var expectedUrl = UrlHelperExtensions.SeoUrl(jobOpportunityId, jobOpportunity.Title.SanitizeUrl());

            if (!expectedUrl.Equals(id, StringComparison.OrdinalIgnoreCase))
            {
                return(RedirectToActionPermanent(nameof(Detail), new { id = expectedUrl }));
            }

            ViewBag.RelatedJobs =
                _jobOpportunityService.GetCompanyRelatedJobs(jobOpportunityId, jobOpportunity.CompanyName);

            ViewBag.CanLike = !CookieHelper.Exists(GetLikeCookieName(jobOpportunityId));

            var cookieView = $"JobView{jobOpportunity.Id}";

            if (IsJobOpportunityOwner(id) || CookieHelper.Exists(cookieView))
            {
                return(jobOpportunity.IsHidden
                    ? View(nameof(Detail), jobOpportunity).WithInfo(Constants.JobDetailWithInfoMessage)
                    : View(nameof(Detail), jobOpportunity));
            }

            _jobOpportunityService.UpdateViewCount(jobOpportunity.Id);
            CookieHelper.Set(cookieView, jobOpportunity.Id.ToString());

            return(jobOpportunity.IsHidden
                ? View(nameof(Detail), jobOpportunity).WithInfo(Constants.JobDetailWithInfoMessage)
                : View(nameof(Detail), jobOpportunity));
        }
コード例 #5
0
        public void Exists_CookieExists_ReturnsTrue()
        {
            // Arrange
            _context.Request.Cookies.Add(new HttpCookie("myKey")
            {
                Value = "myValue"
            });

            // Act
            var exists = CookieHelper.Exists("myKey");

            // Assert
            exists.Should().BeTrue();
        }
コード例 #6
0
        public ActionResult JobDetail(int?Id)
        {
            if (!Id.HasValue)
            {
                return(HomePage());
            }

            var job = jobService.GetById(Id.Value);

            if (job == null)
            {
                return(NotFound());
            }


            if (!job.IsActive || job.IsDelete)
            {
                return(NotFound());
            }

            string cookieKey = string.Format(CookieConstant.PORTFOLIO_VIEW, job.Id);

            if (!CookieHelper.Exists(cookieKey))
            {
                CookieHelper.Set(cookieKey, WebHelper.IpAddress, 1);
                job.ViewCount += 1;
                jobService.Update(job);
            }

            var model = new JobDetailModel
            {
                Id           = job.Id,
                Title        = job.Title,
                Description  = job.Description,
                Url          = job.Url,
                CreateDate   = job.CreateDateUtc,
                UpdateDate   = job.UpdateDateUtc,
                ViewCount    = job.ViewCount,
                SallaryMax   = job.SallaryMax,
                SallaryMin   = job.SallaryMin,
                Location     = job.Location,
                WorkType     = job.JobType,
                CategoryName = job.Category.Name
            };

            model.ApplyJob       = new ApplyJobModel();
            model.ApplyJob.JobId = job.Id;

            return(View(model));
        }
コード例 #7
0
        // GET: /JobOpportunity/Detail/4-jobtitle
        public ActionResult Detail(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Index"));
            }

            var url = id.Split('-');

            if (url.Length == 0)
            {
                return(RedirectToAction("Index"));
            }

            var value = 0;

            if (!int.TryParse(url[0], out value))
            {
                return(RedirectToAction("Index"));
            }

            var vm = _jobOpportunityService.GetJobOpportunityById(value);

            if (vm != null)
            {
                var exceptedUrl = UrlHelperExtensions.SeoUrl(value, vm.Title.SanitizeUrl());

                if (!exceptedUrl.Equals(id))
                {
                    return(RedirectToActionPermanent("Detail", new { id = exceptedUrl }));
                }

                ViewBag.RelatedJobs =
                    _jobOpportunityService.GetCompanyRelatedJobs(value, vm.CompanyName);

                var cookieView = $"JobView{vm.Id}";
                if (!CookieHelper.Exists(cookieView))
                {
                    _jobOpportunityService.UpdateViewCount(vm.Id);
                    CookieHelper.Set(cookieView, vm.Id.ToString());
                }

                return(View("Detail", vm));
            }

            return(View("Index").WithError("La vacante solicitada no existe. Por favor escoge una vacante válida del listado"));
        }
コード例 #8
0
        // GET: /JobOpportunity/Detail/4-jobtitle
        public ActionResult Detail(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(RedirectToAction("Index"));
            }

            var value = GetIdFromTitle(id);

            if (value == 0)
            {
                return(RedirectToAction("Index"));
            }

            var vm = _jobOpportunityService.GetJobOpportunityById(value);

            if (vm != null)
            {
                var expectedUrl = UrlHelperExtensions.SeoUrl(value, vm.Title.SanitizeUrl());

                if (!expectedUrl.Equals(id, StringComparison.OrdinalIgnoreCase))
                {
                    return(RedirectToActionPermanent("Detail", new { id = expectedUrl }));
                }

                ViewBag.RelatedJobs =
                    _jobOpportunityService.GetCompanyRelatedJobs(value, vm.CompanyName);

                var cookieView = $"JobView{vm.Id}";
                if (!CookieHelper.Exists(cookieView))
                {
                    _jobOpportunityService.UpdateViewCount(vm.Id);
                    CookieHelper.Set(cookieView, vm.Id.ToString());
                }

                return(View("Detail", vm));
            }

            return(View("Index").WithError("La vacante solicitada no existe. Por favor escoge una vacante válida del listado"));
        }
コード例 #9
0
        public JsonResult Like(JobOpportunityLike model)
        {
            var cookieName = GetLikeCookieName(model.JobOpportunityId);

            if (CookieHelper.Exists(cookieName))
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { error = true, message = "Ya has votado por este empleo." }));
            }

            _jobOpportunityLikeService.CreateNewLike(model);

            CookieHelper.Set(cookieName, model.JobOpportunityId.ToString());

            var jobLikeData = _jobOpportunityLikeService.GetLikesByJobOpportunityId(model.JobOpportunityId);

            var jobOpportunityLikeData = new JobOpportunityLikeViewModel
            {
                Likes    = jobLikeData.Count(x => x.Like),
                DisLikes = jobLikeData.Count(x => !x.Like)
            };

            return(Json(new { error = false, data = jobOpportunityLikeData }));
        }
コード例 #10
0
        public JsonResult Like(int jobOpportunityId, bool like)
        {
            var cookieName = GetLikeCookieName(jobOpportunityId);

            if (CookieHelper.Exists(cookieName))
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json(new { error = true, message = "Ya has votado por este empleo." }));
            }

            _jobOpportunityService.CreateNewReaction(jobOpportunityId, like);

            CookieHelper.Set(cookieName, jobOpportunityId.ToString());

            var jobOpportunity = _jobOpportunityService.GetJobOpportunityById(jobOpportunityId);

            return(jobOpportunity == null
                ? Json(new { error = true, message = "No se encuentra empleo con el id indicado" })
                : Json(new { error = false, data = new
                             {
                                 jobOpportunity.Likes,
                                 jobOpportunity.DisLikes
                             } }));
        }
コード例 #11
0
ファイル: PostController.cs プロジェクト: lantirn/SefacanBlog
        public ActionResult Index(int?Id)
        {
            if (!Id.HasValue)
            {
                return(HomePage());
            }

            var post = postService.GetById(Id.Value);

            if (post == null)
            {
                return(NotFound());
            }

            if (!post.IsActive || post.IsDelete)
            {
                return(NotFound());
            }

            string cookieKey = string.Format(CookieConstant.POST_VIEW, post.Id);

            if (!CookieHelper.Exists(cookieKey))
            {
                CookieHelper.Set(cookieKey, WebHelper.IpAddress, 1);
                post.ViewCount += 1;
                postService.UpdatePost(post);
            }

            var model = new PostDetailModel
            {
                Id           = post.Id,
                Title        = post.Title,
                FullContent  = post.FullContent,
                PicturePath  = post.PicturePath,
                Url          = urlService.GetUrl(post.Id, Core.Enums.EntityType.Post),
                CreateDate   = post.CreateDate,
                UpdateDate   = post.UpdateDate,
                Description  = post.Description,
                ViewCount    = post.ViewCount,
                CategoryName = categoryService.GetById(post.CategoryId).Name,
                CategoryUrl  = urlService.GetUrl(post.CategoryId, Core.Enums.EntityType.Category),
                CommentCount = postService.GetCommentCount(post.Id),
                AllowComment = post.AllowComment,
                Tags         = tagService.GetTags(postId: post.Id).Select(x => new TagModel
                {
                    Name = x.TagName
                }).ToList()
            };

            if (settingService.GetSetting("post.related.view").BoolValue)
            {
                model.RelatedPosts = postService.GetRelatedPosts(post.CategoryId, post.Id).Select(x => new PostModel
                {
                    Title        = x.Title,
                    PicturePath  = x.PicturePath,
                    ShortContent = x.ShortContent,
                    CreateDate   = x.CreateDate,
                    CategoryName = categoryService.GetById(x.CategoryId).Name,
                    CommentCount = 0,
                    ViewCount    = x.ViewCount,
                    Url          = urlService.GetUrl(x.Id, Core.Enums.EntityType.Post)
                }).ToList();
            }

            if (settingService.GetSetting("post.comment.enabled").BoolValue)
            {
                model.Comments = postService.GetComments(post.Id).Select(x => new CommentListModel
                {
                    Id            = x.Id,
                    ParentId      = x.ParentId,
                    FullName      = x.FullName,
                    Content       = x.Content,
                    CreateDate    = x.CreateDate.ToRelativeFormat(),
                    ChildComments = postService.GetChildComments(post.Id, x.Id).Select(c => new CommentListModel
                    {
                        Id         = c.Id,
                        ParentId   = c.ParentId,
                        FullName   = c.FullName,
                        Content    = c.Content,
                        CreateDate = c.CreateDate.ToRelativeFormat(),
                    }).ToList()
                }).ToList();
            }

            return(View(model));
        }
コード例 #12
0
        public ActionResult Post(int?Id)
        {
            if (!Id.HasValue)
            {
                return(HomePage());
            }

            var post = postService.GetById(Id.Value);

            if (post == null)
            {
                return(NotFound());
            }

            if (!post.IsActive || post.IsDelete)
            {
                return(NotActive());
            }

            string cookieKey = string.Format(CookieConstant.POST_VIEW, post.Id);

            if (!CookieHelper.Exists(cookieKey))
            {
                CookieHelper.Set(cookieKey, WebHelper.IpAddress, 1);
                post.ViewCount += 1;
                postService.Update(post);
            }

            var model = new PostDetailModel
            {
                Id              = post.Id,
                Title           = post.Title,
                Content         = post.Description,
                PicturePath     = post.Picture.FilePath,
                Url             = urlService.GetUrl(post.Id, nameof(Post)),
                User            = post.User,
                CreateDate      = post.CreateDateUtc,
                UpdateDate      = post.UpdateDateUtc,
                ViewCount       = post.ViewCount,
                CategoryName    = post.Category.Name,
                CategoryUrl     = post.Category.Url,
                AllowComment    = post.AllowComment,
                PostFormat      = post.Format,
                PostFormatValue = post.FormatValue,
                ApproveComment  = post.ApproveComment,
                CommentCount    = postService.GetCommentCount(post.Id, true),
                Tags            = tagService.GetTagsByPostId(postId: post.Id).Select(x => new TagModel
                {
                    Name = x.Name
                }).ToList()
            };

            model.User.SocialNetworks = post.User.SocialNetworks;

            if (settingService.GetByName("post.related.view").BoolValue)
            {
                model.RelatedPosts = postService.GetRelatedPosts(post.CategoryId, post.Id).Select(x => new PostModel
                {
                    Id           = x.Id,
                    Title        = x.Title,
                    PicturePath  = mediaStorageService.GetPictureUrl(x.PictureId),
                    CreateDate   = x.CreateDateUtc,
                    CategoryName = categoryService.GetById(x.CategoryId).Name,
                    User         = userService.FindByIdAsync(x.UserId).Result,
                    CommentCount = 0,
                    ViewCount    = x.ViewCount,
                    Url          = urlService.GetUrl(x.Id, nameof(Post))
                }).ToList();
            }

            if (settingService.GetByName("post.comment.enabled").BoolValue)
            {
                model.Comments = postService.GetComments(post.Id, true).Select(x => new CommentListModel
                {
                    Id            = x.Id,
                    ParentId      = x.ParentId,
                    FullName      = x.FullName,
                    Comment       = x.Commentary,
                    UserId        = x.UserId,
                    UserAvatarUrl = userService.GetById(x.UserId).Avatar.FilePath,
                    Approved      = x.Approved,
                    CreateDate    = x.CommentDateUtc.ToRelativeFormat(),
                    ChildComments = postService.GetChildComments(post.Id, x.Id, approved: true).Select(c => new CommentListModel
                    {
                        Id            = c.Id,
                        ParentId      = c.ParentId,
                        FullName      = c.FullName,
                        Comment       = c.Commentary,
                        UserId        = c.UserId,
                        UserAvatarUrl = userService.GetById(x.UserId).Avatar.FilePath,
                        Approved      = c.Approved,
                        CreateDate    = c.CommentDateUtc.ToRelativeFormat(),
                    }).ToList()
                }).ToList();
            }

            return(View(this.GetViewName(post), model));
        }