コード例 #1
0
        public async Task <ActionResult> Edit(Candidate model)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            string    email = AuthorizationTools.GetEmail(User);
            Candidate us    = _context.Candidates.Where(c => c.EmailAddress == email).First();

            if (role != Role.ADMIN && (us == null || us.Id != model.Id))
            {
                return(new UnauthorizedResult());
            }

            if (!ModelState.IsValid)
            {
                return(View());
            }

            var candidate = await _context.Candidates.FirstOrDefaultAsync(x => x.Id == model.Id);

            candidate.FirstName    = model.FirstName;
            candidate.LastName     = model.LastName;
            candidate.EmailAddress = model.EmailAddress;
            candidate.PhoneNumber  = model.PhoneNumber;
            _context.Update(candidate);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = model.Id }));
        }
コード例 #2
0
        public async Task <ActionResult> Delete(int?id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role == Role.CANDIDATE)
            {
                return(new UnauthorizedResult());
            }

            if (id == null)
            {
                return(BadRequest($"id should not be null"));
            }
            var offer = await _context.JobOffers.Include(x => x.HR).FirstOrDefaultAsync(x => x.Id == id.Value);

            if (role == Role.HR)
            {
                string email = AuthorizationTools.GetEmail(User);
                HR     us    = _context.HRs.Where(h => h.EmailAddress == email).First();
                if (us.Id != offer.HR.Id)
                {
                    return(new UnauthorizedResult());
                }
            }
            List <Application> apps = await _context.JobApplications.Where(x => x.JobOffer == offer).ToListAsync();

            _context.JobApplications.RemoveRange(apps);
            _context.JobOffers.Remove(offer);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public async Task <ActionResult> Create(JobOffer model)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role != Role.HR)
            {
                return(new UnauthorizedResult());
            }

            if (!ModelState.IsValid || (model.SalaryFrom != null && model.SalaryTo != null && model.SalaryFrom > model.SalaryTo))
            {
                return(View(model));
            }
            string   email = AuthorizationTools.GetEmail(User);
            HR       us    = _context.HRs.Where(h => h.EmailAddress == email).First();
            JobOffer jo    = new JobOffer
            {
                Description = model.Description,
                JobTitle    = model.JobTitle,
                Location    = model.Location,
                SalaryFrom  = model.SalaryFrom,
                SalaryTo    = model.SalaryTo,
                ValidUntil  = model.ValidUntil,
                Created     = DateTime.Now,
                HR          = us
            };

            await _context.JobOffers.AddAsync(jo);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
コード例 #4
0
        public async Task <ActionResult> Create(int id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));

            if (role != Role.CANDIDATE)
            {
                return(new UnauthorizedResult());
            }
            JobOffer  offer     = _context.JobOffers.Where(o => o.Id == id).First();
            string    email     = AuthorizationTools.GetEmail(User);
            Candidate candidate = _context.Candidates.Where(c => c.EmailAddress == email).First();
            var       model     = new Application()
            {
                FirstName    = candidate.FirstName,
                LastName     = candidate.LastName,
                PhoneNumber  = candidate.PhoneNumber,
                CvUrl        = "TODO",
                EmailAddress = email,
                JobOffer     = offer,
                Candidate    = candidate
            };

            return(View(model));
        }
コード例 #5
0
        public async Task <ActionResult> DeleteCommentAjax(int id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));

            if (role != Role.HR)
            {
                return(new UnauthorizedResult());
            }
            Comment comment = _context.Comments
                              .Include(x => x.Application)
                              .Include(x => x.Application.JobOffer)
                              .Include(x => x.Application.JobOffer.HR)
                              .Where(a => a.Id == id).FirstOrDefault();

            if (comment == null)
            {
                return(new UnauthorizedResult());
            }
            Application app   = comment.Application;
            string      email = AuthorizationTools.GetEmail(User);
            HR          hr    = _context.HRs.Where(c => c.EmailAddress == email).First();

            if (comment.Application.JobOffer.HR != hr)
            {
                return(new UnauthorizedResult());
            }

            _context.Comments.Remove(comment);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = app.Id }));
        }
コード例 #6
0
        public async Task <IActionResult> Details(int id)
        {
            var offer = await _context.JobOffers
                        .Include(x => x.HR)
                        .Include(x => x.HR.Company)
                        .FirstOrDefaultAsync(x => x.Id == id);

            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role == Role.HR)
            {
                JobOfferDetailsHRView jobOfferDetailsHRView = new JobOfferDetailsHRView();
                jobOfferDetailsHRView.Offer = offer;
                string email = AuthorizationTools.GetEmail(User);
                HR     us    = _context.HRs.Where(h => h.EmailAddress == email).First();
                jobOfferDetailsHRView.HR           = us;
                jobOfferDetailsHRView.Applications = await _context.JobApplications.Where(ja => ja.JobOffer == offer).ToListAsync();

                return(View("DetailsHR", jobOfferDetailsHRView));
            }
            if (role == Role.ADMIN)
            {
                return(View("DetailsAdmin", offer));
            }
            return(View("DetailsCandidate", offer));
        }
コード例 #7
0
ファイル: HRController.cs プロジェクト: JakubBilski/pracujpl2
        public async Task <ActionResult> Create(HRCreateView model)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role != Role.ADMIN)
            {
                return(new UnauthorizedResult());
            }
            if (!ModelState.IsValid)
            {
                model.Companies = await _context.Companies.ToListAsync();

                return(View(model));
            }

            HR hr = new HR
            {
                FirstName    = model.FirstName,
                LastName     = model.LastName,
                CompanyId    = model.CompanyId,
                EmailAddress = model.EmailAddress
            };

            await _context.HRs.AddAsync(hr);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
コード例 #8
0
        public async Task <IActionResult> Edit(int?id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role == Role.CANDIDATE)
            {
                return(new UnauthorizedResult());
            }
            if (id == null)
            {
                return(BadRequest($"id shouldn't be null"));
            }
            var offer = await _context.JobOffers.FirstOrDefaultAsync(x => x.Id == id.Value);

            if (offer == null)
            {
                return(NotFound($"offer not found in DB"));
            }
            if (role == Role.HR)
            {
                string email = AuthorizationTools.GetEmail(User);
                HR     us    = _context.HRs.Where(h => h.EmailAddress == email).First();
                if (us.Id != offer.HR.Id)
                {
                    return(new UnauthorizedResult());
                }
            }

            return(View(offer));
        }
コード例 #9
0
ファイル: HRController.cs プロジェクト: JakubBilski/pracujpl2
        public async Task <IActionResult> Details(int id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            string email = AuthorizationTools.GetEmail(User);
            HR     us    = _context.HRs.Where(h => h.EmailAddress == email).FirstOrDefault();

            if (role != Role.ADMIN && (us == null || us.Id != id))
            {
                return(new UnauthorizedResult());
            }

            if (role == Role.CANDIDATE)
            {
                return(new UnauthorizedResult());
            }
            var hr = await _context.HRs
                     .Include(x => x.Company)
                     .FirstOrDefaultAsync(x => x.Id == id);

            if (role == Role.ADMIN)
            {
                return(View("DetailsAdmin", hr));
            }
            return(View("DetailsHR", hr));
        }
コード例 #10
0
        public async Task <IActionResult> Index([FromQuery(Name = "search")] string searchString)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            List <Company> searchResult;

            if (string.IsNullOrEmpty(searchString))
            {
                searchResult = await _context.Companies.ToListAsync();
            }
            else
            {
                searchResult = await _context
                               .Companies
                               .Where(o => o.Name.Contains(searchString, StringComparison.OrdinalIgnoreCase))
                               .ToListAsync();
            }

            if (role == Role.ADMIN)
            {
                return(View("IndexAdmin", searchResult));
            }
            return(View("IndexHRAndCandidate", searchResult));
        }
コード例 #11
0
ファイル: HRController.cs プロジェクト: JakubBilski/pracujpl2
        public async Task <IActionResult> Edit(int?id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            string email = AuthorizationTools.GetEmail(User);
            HR     us    = _context.HRs.Where(h => h.EmailAddress == email).FirstOrDefault();

            if (await AuthorizationTools.IsAdmin(User, _context) == false && (us == null || us.Id != id.Value))
            {
                return(new UnauthorizedResult());
            }

            if (id == null)
            {
                return(BadRequest($"id shouldn't not be null"));
            }
            var hr = await _context.HRs.FirstOrDefaultAsync(x => x.Id == id.Value);

            if (hr == null)
            {
                return(NotFound($"HR not found in DB"));
            }

            return(View(hr));
        }
コード例 #12
0
        public async Task <IActionResult> Edit(int?id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            string    email = AuthorizationTools.GetEmail(User);
            Candidate us    = _context.Candidates.Where(c => c.EmailAddress == email).First();

            if (role != Role.ADMIN && (us == null || us.Id != id.Value))
            {
                return(new UnauthorizedResult());
            }

            if (id == null)
            {
                return(BadRequest($"id shouldn't not be null"));
            }
            var offer = await _context.Candidates.FirstOrDefaultAsync(x => x.Id == id.Value);

            if (offer == null)
            {
                return(NotFound($"offer not found in DB"));
            }
            return(View(offer));
        }
コード例 #13
0
ファイル: HRController.cs プロジェクト: JakubBilski/pracujpl2
        public async Task <ActionResult> Edit(HR model)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            string email = AuthorizationTools.GetEmail(User);
            HR     us    = _context.HRs.Where(h => h.EmailAddress == email).FirstOrDefault();

            if (await AuthorizationTools.IsAdmin(User, _context) == false && (us == null || us.Id != model.Id))
            {
                return(new UnauthorizedResult());
            }

            if (!ModelState.IsValid)
            {
                return(View());
            }

            var hr = await _context.HRs.FirstOrDefaultAsync(x => x.Id == model.Id);

            hr.FirstName    = model.FirstName;
            hr.LastName     = model.LastName;
            hr.Company      = model.Company;
            hr.EmailAddress = model.EmailAddress;
            _context.Update(hr);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = model.Id }));
        }
コード例 #14
0
        public async Task <ActionResult> Create()
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role != Role.ADMIN)
            {
                return(new UnauthorizedResult());
            }
            return(View());
        }
コード例 #15
0
        public async Task <ActionResult> Create()
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role != Role.HR)
            {
                return(new UnauthorizedResult());
            }
            var model = new JobOffer();

            return(View(model));
        }
コード例 #16
0
        public async Task <IActionResult> Details(int id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role != Role.ADMIN)
            {
                return(new UnauthorizedResult());
            }
            var model = _context.Companies.Find(id);

            return(View("Details", model));
        }
コード例 #17
0
        public async Task <IActionResult> Index()
        {
            if (User != null && User.Identity.IsAuthenticated)
            {
                Role role = await AuthorizationTools.GetRoleAsync(User, _context);

                ViewData.Add("role", role);
                ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            }
            else
            {
                ViewData.Add("role", Role.CANDIDATE);
            }

            return(View());
        }
コード例 #18
0
        public async Task <IActionResult> Details(int id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            string email = AuthorizationTools.GetEmail(User);

            if (role == Role.ADMIN)
            {
                return(new UnauthorizedResult());
            }

            Application app = _context.JobApplications
                              .Include(x => x.JobOffer)
                              .Include(x => x.Candidate)
                              .Include(x => x.JobOffer.HR)
                              .Include(x => x.JobOffer.HR.Company)
                              .Include(x => x.Comments)
                              .Where(a => a.Id == id)
                              .FirstOrDefault();

            if (app == null)
            {
                return(new NotFoundResult());
            }
            if (role == Role.HR)
            {
                HR us = _context.HRs.Where(c => c.EmailAddress == email).FirstOrDefault();
                if (us == null || us.Id != app.JobOffer.HR.Id)
                {
                    return(new UnauthorizedResult());
                }
                ApplicationWithComment appWithComm = new ApplicationWithComment(app);
                return(View("DetailsHR", appWithComm));
            }
            else
            {
                Candidate us = _context.Candidates.Where(c => c.EmailAddress == email).FirstOrDefault();
                if (us == null || us.Id != app.Candidate.Id)
                {
                    return(new UnauthorizedResult());
                }

                return(View("DetailsCandidate", app));
            }
        }
コード例 #19
0
ファイル: HRController.cs プロジェクト: JakubBilski/pracujpl2
        public async Task <ActionResult> Create()
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (await AuthorizationTools.IsAdmin(User, _context) == false)
            {
                return(new UnauthorizedResult());
            }
            var model = new HRCreateView
            {
                Companies = await _context.Companies.ToListAsync()
            };

            return(View(model));
        }
コード例 #20
0
        public async Task <IActionResult> Index([FromQuery(Name = "search")] string searchString)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            List <JobOffer> searchResult;

            if (string.IsNullOrEmpty(searchString))
            {
                searchResult = await _context.JobOffers
                               .Include(x => x.HR)
                               .Include(x => x.HR.Company)
                               .ToListAsync();
            }
            else
            {
                searchResult = await _context
                               .JobOffers
                               .Include(x => x.HR)
                               .Include(x => x.HR.Company)
                               .Where(o => o.JobTitle.Contains(searchString, StringComparison.OrdinalIgnoreCase) ||
                                      o.HR.Company.Name.Contains(searchString, StringComparison.OrdinalIgnoreCase))
                               .ToListAsync();
            }
            string email = AuthorizationTools.GetEmail(User);

            if (role == Role.HR)
            {
                JobOfferIndexHRView jobOfferIndexHRView = new JobOfferIndexHRView();
                jobOfferIndexHRView.Offers = searchResult;
                HR us = _context.HRs.Where(h => h.EmailAddress == email).First();
                jobOfferIndexHRView.HR = us;
                return(View("IndexHR", jobOfferIndexHRView));
            }
            else if (role == Role.CANDIDATE)
            {
                JobOfferIndexCandidateView jobOfferIndexCandidateView = new JobOfferIndexCandidateView();
                jobOfferIndexCandidateView.Offers = searchResult;
                Candidate us = _context.Candidates.Where(c => c.EmailAddress == email).First();
                jobOfferIndexCandidateView.Candidate = us;
                return(View("IndexCandidate", jobOfferIndexCandidateView));
            }
            //role == Role.ADMIN
            return(View("IndexAdmin", searchResult));
        }
コード例 #21
0
        public async Task <IActionResult> Index([FromQuery(Name = "search")] string searchString)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            List <Application> searchResult;

            if (string.IsNullOrEmpty(searchString))
            {
                searchResult = await _context.JobApplications
                               .Include(x => x.JobOffer)
                               .Include(x => x.JobOffer.HR)
                               .Include(x => x.JobOffer.HR.Company)
                               .Include(x => x.Comments)
                               .ToListAsync();
            }
            else
            {
                searchResult = await _context
                               .JobApplications
                               .Include(x => x.JobOffer)
                               .Include(x => x.JobOffer.HR)
                               .Include(x => x.JobOffer.HR.Company)
                               .Include(x => x.Comments)
                               .Where(o => o.LastName.Contains(searchString, StringComparison.OrdinalIgnoreCase))
                               .ToListAsync();
            }
            if (role == Role.HR)
            {
                string email = AuthorizationTools.GetEmail(User);
                HR     us    = _context.HRs.Where(h => h.EmailAddress == email).First();
                searchResult = searchResult.Where(a => a.JobOffer.HR == us).ToList();
                return(View("IndexHR", searchResult));
            }
            else if (role == Role.CANDIDATE)
            {
                string    email = AuthorizationTools.GetEmail(User);
                Candidate us    = _context.Candidates.Where(c => c.EmailAddress == email).First();
                searchResult = searchResult.Where(a => a.Candidate == us).ToList();
                return(View("IndexCandidate", searchResult));
            }
            return(View("IndexAdmin", searchResult));
        }
コード例 #22
0
        public async Task <ActionResult> EditConfirmed(Company company)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role != Role.ADMIN)
            {
                return(new UnauthorizedResult());
            }
            if (!ModelState.IsValid)
            {
                return(View());
            }
            _context.Companies.Update(company);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
コード例 #23
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role != Role.ADMIN)
            {
                return(new UnauthorizedResult());
            }
            Company company = _context.Companies.Find(id);

            if (company == null)
            {
                return(NotFound());
            }
            _context.Companies.Remove(company);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
コード例 #24
0
        public async Task <ActionResult> Delete(int?id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role != Role.ADMIN)
            {
                return(new UnauthorizedResult());
            }
            if (id == null)
            {
                return(NotFound());
            }
            Company company = await _context.Companies.FindAsync(id);

            if (company == null)
            {
                return(NotFound());
            }
            return(View(company));
        }
コード例 #25
0
        public async Task <IActionResult> IndexAjax([FromQuery(Name = "search")] string searchString)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role != Role.ADMIN)
            {
                return(new UnauthorizedResult());
            }
            if (string.IsNullOrEmpty(searchString))
            {
                return(new JsonResult(await _context.Candidates.ToListAsync()));
            }

            List <Candidate> searchResult = await _context
                                            .Candidates
                                            .Where(o => o.LastName.Contains(searchString, StringComparison.OrdinalIgnoreCase))
                                            .ToListAsync();

            return(new JsonResult(searchResult));
        }
コード例 #26
0
        public async Task <ActionResult> Edit(JobOffer model)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (role == Role.CANDIDATE)
            {
                return(new UnauthorizedResult());
            }

            if (!ModelState.IsValid || (model.SalaryFrom != null && model.SalaryTo != null && model.SalaryFrom > model.SalaryTo))
            {
                return(View());
            }

            var offer = await _context.JobOffers.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (role == Role.HR)
            {
                string email = AuthorizationTools.GetEmail(User);
                HR     us    = _context.HRs.Where(h => h.EmailAddress == email).First();
                if (us.Id != offer.HR.Id)
                {
                    return(new UnauthorizedResult());
                }
            }
            offer.JobTitle    = model.JobTitle;
            offer.Description = model.Description;
            offer.Location    = model.Location;
            offer.SalaryFrom  = model.SalaryFrom;
            offer.SalaryTo    = model.SalaryTo;
            offer.ValidUntil  = model.ValidUntil;
            _context.Update(offer);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = model.Id }));
        }
コード例 #27
0
        public async Task <ActionResult> CreateCommentAjax(ApplicationWithComment model)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (model.CommentText == "")
            {
                RedirectToAction("Details", new { id = model.Id });
            }
            if (role != Role.HR)
            {
                return(new UnauthorizedResult());
            }
            Application app = _context.JobApplications
                              .Include(x => x.Comments)
                              .Include(x => x.JobOffer)
                              .Include(x => x.JobOffer.HR)
                              .Where(a => a.Id == model.Id).FirstOrDefault();
            string email = AuthorizationTools.GetEmail(User);
            HR     hr    = _context.HRs.Where(c => c.EmailAddress == email).First();

            if (app.JobOffer.HR != hr)
            {
                return(new UnauthorizedResult());
            }

            Comment comm = new Comment()
            {
                Text = model.CommentText, Application = app
            };

            await _context.Comments.AddAsync(comm);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = model.Id }));
        }
コード例 #28
0
ファイル: HRController.cs プロジェクト: JakubBilski/pracujpl2
        public async Task <IActionResult> Index([FromQuery(Name = "search")] string searchString)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (await AuthorizationTools.IsAdmin(User, _context) == false)
            {
                return(new UnauthorizedResult());
            }

            if (string.IsNullOrEmpty(searchString))
            {
                return(View(await _context.HRs.Include(x => x.Company).ToListAsync()));
            }

            List <HR> searchResult = await _context
                                     .HRs.Include(x => x.Company)
                                     .Where(o => o.LastName.Contains(searchString, StringComparison.OrdinalIgnoreCase))
                                     .ToListAsync();

            return(View(searchResult));
        }
コード例 #29
0
ファイル: HRController.cs プロジェクト: JakubBilski/pracujpl2
        public async Task <ActionResult> Delete(int?id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            if (await AuthorizationTools.IsAdmin(User, _context) == false)
            {
                return(new UnauthorizedResult());
            }
            if (id == null)
            {
                return(BadRequest($"id should not be null"));
            }

            _context.HRs.Remove(new HR()
            {
                Id = id.Value
            });
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
コード例 #30
0
        public async Task <IActionResult> Details(int id)
        {
            Role role = await AuthorizationTools.GetRoleAsync(User, _context);

            ViewData.Add("role", role);
            ViewData.Add("id", AuthorizationTools.GetUserDbId(User, _context, role));
            string    email = AuthorizationTools.GetEmail(User);
            Candidate us    = _context.Candidates.Where(c => c.EmailAddress == email).FirstOrDefault();

            if (role != Role.ADMIN && (us == null || us.Id != id))
            {
                return(new UnauthorizedResult());
            }

            var candidate = await _context.Candidates
                            .FirstOrDefaultAsync(x => x.Id == id);

            if (role == Role.ADMIN)
            {
                return(View("DetailsAdmin", candidate));
            }
            return(View("DetailsCandidate", candidate));
        }