Esempio n. 1
0
        public async Task <ActionResult> Create(JobOfferCreateView model)
        {
            if (!ModelState.IsValid)
            {
                model.Companies = await _context.Companies.ToListAsync();

                return(View(model));
            }

            JobOffer offer = new JobOffer
            {
                CreatorId   = User.GetId(),
                CompanyId   = model.CompanyId,
                Description = model.Description,
                JobTitle    = model.JobTitle,
                Location    = model.Location,
                SalaryFrom  = model.SalaryFrom,
                SalaryTo    = model.SalaryTo,
                ValidUntil  = model.ValidUntil,
                Created     = DateTime.Now,
            };

            await _context.JobOffers.AddAsync(offer);

            await _context.SaveChangesAsync();

            return(RedirectToAction("IndexHR"));
        }
        public async Task <IActionResult> UpdateStatus(int?id, int?status)
        {
            if (id == null || status == null || !Enum.IsDefined(typeof(ApplicationStatus), status.Value))
            {
                return(BadRequest());
            }

            JobApplication app = await _context.JobApplications.Include(x => x.JobOffer).FirstOrDefaultAsync(app => app.Id == id);

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

            if (app.JobOffer.CreatorId != User.GetId())
            {
                return(Forbid());
            }

            app.Status = (ApplicationStatus)status.Value;
            _context.Update(app);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(DetailsHR), "JobOffers", new { id = app.JobOfferId }));
        }
        public async Task <IActionResult> Create(Company company)
        {
            if (ModelState.IsValid)
            {
                _context.Add(company);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(BadRequest());
        }
Esempio n. 4
0
        public async Task <IActionResult> UpdateRole(int?id, int?roleId)
        {
            if (id == null || roleId == null)
            {
                return(BadRequest());
            }

            var user = await _context.Users.Where(x => x.RoleId != 3).FirstOrDefaultAsync(u => u.Id == id);

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

            user.RoleId = roleId.Value;
            _context.Update(user);
            await _context.SaveChangesAsync();

            return(Ok());
        }