예제 #1
0
        public IActionResult New(NewJobViewModel newJobViewModel)
        {
            //  #6 - Validate the ViewModel and if valid, create a
            // new Job and add it to the JobData data store. Then
            // redirect to the Job detail (Index) action/view for the new Job.
            if (newJobViewModel != null && newJobViewModel.Name != null && newJobViewModel.Name.Trim().Length != 0)
            {
                Models.Employer       employer       = jobData.Employers.Find(newJobViewModel.EmployerID);
                Models.Location       location       = jobData.Locations.Find(newJobViewModel.LocationID);
                Models.PositionType   positionType   = jobData.PositionTypes.Find(newJobViewModel.PositionTypeID);
                Models.CoreCompetency coreCompetency = jobData.CoreCompetencies.Find(newJobViewModel.CoreCompetencyID);

                Models.Job newJob = new Models.Job
                {
                    Name           = newJobViewModel.Name,
                    Employer       = employer,
                    Location       = location,
                    PositionType   = positionType,
                    CoreCompetency = coreCompetency
                };
                jobData.Jobs.Add(newJob);

                return(View("Index", newJob));
            }

            return(View(newJobViewModel));
        }
예제 #2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Employer = await _context.Employer.FirstOrDefaultAsync(m => m.Id == id);

            if (Employer == null)
            {
                return(NotFound());
            }
            return(Page());
        }
예제 #3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Employer = await _context.Employer.FindAsync(id);

            await _context.Entry(Employer).Collection(s => s.Jobs).LoadAsync();

            await _context.Entry(Employer).Collection(s => s.Contacts).LoadAsync();

            if (Employer != null)
            {
                _context.Employer.Remove(Employer);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
예제 #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var emptyEmployer = new Models.Employer();

            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            emptyEmployer.ApplicationUserId = userId;

            if (await TryUpdateModelAsync(
                    emptyEmployer,
                    "employer",
                    e => e.ApplicationUserId,
                    e => e.Name,
                    e => e.Address1,
                    e => e.Address2,
                    e => e.City,
                    e => e.PhoneNumber,
                    e => e.State,
                    e => e.WebSite,
                    e => e.ZipCode,
                    e => e.Description
                    ))
            {
                _context.Employer.Add(emptyEmployer);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            return(Page());
        }