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 })); }
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)); }
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 })); }
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)); }
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")); }
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")); }
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)); }
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 })); }
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)); }
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)); }
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)); }
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 })); }
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)); } }
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)); }
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)); }
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)); }
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 })); }
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 })); }
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)); }
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)); string email = AuthorizationTools.GetEmail(User); if (role != Role.CANDIDATE) { return(new UnauthorizedResult()); } if (id == null) { return(NotFound()); } 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(NotFound()); } Candidate us = _context.Candidates.Where(c => c.EmailAddress == email).FirstOrDefault(); if (us == null || app.State != "Pending" || us.Id != app.Candidate.Id) { return(new UnauthorizedResult()); } return(View(app)); }
public async Task <ActionResult> RejectConfirmed(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.HR) { 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(NotFound()); } HR us = _context.HRs.Where(c => c.EmailAddress == email).FirstOrDefault(); if (us == null || app.State != "Pending" || us.Id != app.JobOffer.HR.Id) { return(new UnauthorizedResult()); } app.State = "Rejected"; await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Create([Bind("Id, FirstName, LastName, PhoneNumber, EmailAddress, ContactAgreement, CvUrl, File, State, JobOffer, Candidate")] Application 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()); } JobOffer offer = _context.JobOffers.Include(x => x.HR).Where(o => o.Id == model.Id).First(); string email = AuthorizationTools.GetEmail(User); Candidate candidate = _context.Candidates.Where(c => c.EmailAddress == email).First(); if (!ModelState.IsValid) { return(View()); } var uploads = Path.Combine(_env.WebRootPath, "uploads"); bool exists = Directory.Exists(uploads); if (!exists) { Directory.CreateDirectory(uploads); } var fileName = Path.GetFileName(model.File.FileName); var fileStream = new FileStream(Path.Combine(uploads, model.File.FileName), FileMode.Create); string mimeType = model.File.ContentType; byte[] fileData = null; using (var memoryStream = new MemoryStream()) { model.File.CopyTo(memoryStream); fileData = memoryStream.ToArray(); } model.CvUrl = _blob.UploadFileToBlob(model.File.FileName, fileData, mimeType); Application application = new Application() { FirstName = model.FirstName, LastName = model.LastName, EmailAddress = model.EmailAddress, PhoneNumber = model.PhoneNumber, CvUrl = model.CvUrl, ContactAgreement = model.ContactAgreement, Comments = model.Comments, Candidate = candidate, JobOffer = offer, State = "Pending" }; await _context.JobApplications.AddAsync(application); await _context.SaveChangesAsync(); var apiKey = "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"; var client = new SendGridClient(apiKey); var from = new EmailAddress("*****@*****.**", "HRMiniApp"); var subject = "New application"; var to = new EmailAddress(offer.HR.EmailAddress); var plainTextContent = ""; var htmlContent = $"<strong>Your Job Offer received new Application: <a href=https://localhost:5001/Application/Details/{ model.Id}>link</a> </strong>"; var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); var attachment = new Attachment() { Content = Convert.ToBase64String(fileData), Filename = "cv.pdf" }; msg.AddAttachment(attachment); var response = await client.SendEmailAsync(msg); return(RedirectToAction("Index")); }