Ejemplo n.º 1
0
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(BadRequest("Id cannot be null"));
            }

            int?creatorId = _context.JobOffers.Where(off => off.Id == id).Select(off => off.CreatorId).FirstOrDefault();

            if (!creatorId.HasValue)
            {
                return(RedirectToAction("IndexHR"));
            }

            if (User.GetId() != creatorId)
            {
                return(Forbid());
            }

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

            return(RedirectToAction("IndexHR"));
        }
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(BadRequest("Id cannot be null"));
            }

            int?creatorId = _context.JobApplications.Where(app => app.Id == id).Select(app => app.CreatorId).FirstOrDefault();

            if (creatorId != User.GetId())
            {
                return(Forbid());
            }

            if (!creatorId.HasValue)
            {
                return(RedirectToAction("Index"));
            }

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

            return(RedirectToAction("Index"));
        }