예제 #1
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"));
        }
예제 #2
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));
        }
예제 #3
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));
        }
예제 #4
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 }));
        }
예제 #5
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));
        }
예제 #6
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"));
        }
예제 #7
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));
        }
예제 #8
0
        public async Task <ActionResult> Edit(Application model)
        {
            string    email = AuthorizationTools.GetEmail(User);
            Candidate us    = _context.Candidates.Where(h => h.EmailAddress == email).FirstOrDefault();
            var       app   = await _context.JobApplications.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (us == null || app == null || app.State != "Pending" || us.Id != app.Candidate.Id)
            {
                return(new UnauthorizedResult());
            }

            //if (!ModelState.IsValid)
            //{
            //    return View();
            //}
            app.FirstName        = model.FirstName;
            app.LastName         = model.LastName;
            app.PhoneNumber      = model.PhoneNumber;
            app.EmailAddress     = model.EmailAddress;
            app.ContactAgreement = model.ContactAgreement;
            app.CvUrl            = model.CvUrl;
            _context.Update(app);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = model.Id }));
        }
예제 #9
0
        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"));
        }
예제 #10
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 }));
        }
예제 #11
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);
            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));
        }
예제 #12
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));
        }
예제 #13
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);
            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));
        }
예제 #14
0
        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 }));
        }
예제 #15
0
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     if (AuthorizationTools.IsAuthorization())
     {
         return;
     }
     if (this.NavigationService != null)
     {
         this.NavigationService.Navigate(new BookAuthorise());
     }
 }
예제 #16
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());
        }
예제 #17
0
        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var code = this.authorcode.Text.Trim();

            if (!AuthorizationTools.SetAuthorizationCode(code))
            {
                return;
            }
            if (this.NavigationService != null)
            {
                this.NavigationService.Navigate(new BookSearch());
            }
        }
예제 #18
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));
        }
예제 #19
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));
        }
예제 #20
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());
        }
예제 #21
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));
            }
        }
예제 #22
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 (await AuthorizationTools.IsAdmin(User, _context) == false)
            {
                return(new UnauthorizedResult());
            }
            var model = new HRCreateView
            {
                Companies = await _context.Companies.ToListAsync()
            };

            return(View(model));
        }
예제 #23
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(BadRequest($"id shouldn't not be null"));
            }
            string    email = AuthorizationTools.GetEmail(User);
            Candidate us    = _context.Candidates.Where(h => h.EmailAddress == email).FirstOrDefault();
            var       app   = await _context.JobApplications.FirstOrDefaultAsync(x => x.Id == id.Value);

            if (us == null || app == null || app.State != "Pending" || us.Id != app.Candidate.Id)
            {
                return(new UnauthorizedResult());
            }

            return(View(app));
        }
예제 #24
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));
        }
예제 #25
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));
        }
예제 #26
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"));
        }
예제 #27
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"));
        }
예제 #28
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));
        }
예제 #29
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));
        }
예제 #30
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 }));
        }