public async Task <IActionResult> Edit(int id, JobCreateViewModel viewModel)
        {
            var job = viewModel.Job;

            if (id != job.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(job);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!JobExists(job.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "EmailAddress", viewModel.Job.CustomerId);
            return(View(viewModel.Job));
        }
        public async Task <IActionResult> CreateCompany(JobCreateViewModel newJob)
        {
            var user = await GetCurrentUserAsync();

            // If the user is already in the ModelState
            // Remove user from model state
            ModelState.Remove("Job.User");
            ModelState.Remove("Job.UserId");
            ModelState.Remove("UserCompany.User");
            ModelState.Remove("UserCompany.UserId");

            // If model state is valid
            if (ModelState.IsValid)
            {
                //Add user to model
                newJob.UserCompany.User = user;

                //Add userId to Model
                newJob.UserCompany.UserId = user.Id;
                //If a user enters a new company name
                if (newJob.UserCompany.Name != null)
                {
                    //Add that company to the database
                    _context.Add(newJob.UserCompany);

                    await _context.SaveChangesAsync();
                }
                // Redirect to details view with id of product made using new object
                return(RedirectToAction(nameof(Create)));
            }
            return(View(newJob));
        }
        // GET: Jobs/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            var currentUser = await _userManager.GetUserAsync(HttpContext.User);

            List <Customer> customers = await _context.Customers.Where(c => c.UserId == currentUser.Id).ToListAsync();

            var job = await _context.Jobs.FindAsync(id);

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

            var viewModel = new JobCreateViewModel()
            {
                Job             = job,
                CustomerOptions = customers.Select(c => new SelectListItem
                {
                    Value = c.Id.ToString(),
                    Text  = c.FirstName + " " + c.LastName
                }).ToList()
            };

            ViewData["CustomerId,"] = new SelectList(_context.Customers, "Id", "EmailAddress");
            return(View(viewModel));
        }
        public async Task <IActionResult> Create(JobCreateViewModel viewModel)
        {
            //Remove User, UserId and IsActive
            ModelState.Remove("Job.User");
            ModelState.Remove("Job.UserId");

            ModelState.Remove("Job.Company");


            //Check if model state is valid
            if (ModelState.IsValid)
            {
                //Get current user
                ApplicationUser user = await GetCurrentUserAsync();

                //Add user to Model
                viewModel.Job.User   = user;
                viewModel.Job.UserId = user.Id;

                //Set IsActive
                viewModel.Job.IsActive = true;

                _context.Add(viewModel.Job);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }

            return(View(viewModel));
        }
Пример #5
0
 public ActionResult Create(JobCreateViewModel viewModel, Guid[] AttachmentId, string[] AttachmentName)
 {
     if (ModelState.IsValid)
     {
         var transaction = NHibernateSession.Current.BeginTransaction();
         try
         {
             var id = Guid.NewGuid();
             _jobService.CreateJob(id, viewModel.Instructions, viewModel.OrderNumber, viewModel.AdviceNumber, viewModel.TypeId, viewModel.CustomerId, viewModel.Notes, viewModel.Contact);
             if (AttachmentId != null)
             {
                 for (var i = 0; i < AttachmentId.Length; i++)
                 {
                     _jobService.AddAttachment(id, AttachmentId[i], AttachmentName[i]);
                 }
             }
             transaction.Commit();
             return(RedirectToAction("PendingJobs"));
         }
         catch (DomainValidationException dex)
         {
             transaction.Rollback();
             ModelState.UpdateFromDomain(dex.Result);
         }
         finally
         {
             transaction.Dispose();
         }
     }
     return(View(viewModel));
 }
Пример #6
0
        public ActionResult Create()
        {
            var jobViewModel = new JobCreateViewModel()
            {
                CreatedBy = "Graham Robertson",    // Hard coded for now.
                JobTypes  = _listItemService.GetAllByCategory(ListItemCategoryType.JobType).ToSelectList(),
            };

            return(View(jobViewModel));
        }
Пример #7
0
        //GET: Jobs/Create
        public async Task <IActionResult> Create()
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            var viewModel = new JobCreateViewModel()
            {
                Customers = await _context.Customer.Where(c => c.UserId == user.Id).OrderBy(c => c.FirstName).ToListAsync(),
                Services  = await _context.Service.Where(s => s.UserId == user.Id && s.IsDeleted == false).OrderBy(s => s.Name).ToListAsync()
            };

            return(View(viewModel));
        }
Пример #8
0
        // GET: Jobs/Create
        public IActionResult Create()
        {
            ViewData["ApplicationUserId"] = new SelectList(_context.ApplicationUser, "Id", "Id");

            //ViewData["CompanyId"] = new SelectList(_context.Company, "CompanyId", "Location");

            JobCreateViewModel JobCreateViewModel = new JobCreateViewModel(_context);

            return(View(JobCreateViewModel));

            //ViewData["StatusId"] = new SelectList(_context.Status, "StatusId", "Name");
            //return View();
        }
Пример #9
0
        public async Task <IActionResult> Create(JobCreateViewModel jobVM) // [Bind("Title,Description,IsDraft,MinSalary,MaxSalary,WorkingHoursStart,WorkingHoursEnd,HoursPerWeek,HolidayEntitlement,ClosingDate,PublishDate,Id,CreatedDate,UpdatedDate,IsActive")]
        {
            if (ModelState.IsValid)
            {
                var job = _mapper.Map <Job>(jobVM);
                await _service.Post(job);

                await _jobBenefitsService.CreateOrUpdateJobBenefitsForJob(job.Id, new List <Job_JobBenefit>(), jobVM.JobBenefitsIds);

                return(RedirectToAction(nameof(Index)).WithSuccess("Success", "Job sucessfully created!"));
            }
            return(View(jobVM).WithDanger("Error", "Some errors occured creating the job"));
        }
        // GET: Jobs/Create

        public async Task <IActionResult> Create()
        {
            //get current user
            var user = await GetCurrentUserAsync();

            //get all the companies from database
            List <Company> AllCompanies = await _context.Company.Where(c => c.UserId == user.Id).ToListAsync();

            //creating a select list of companies
            List <SelectListItem> usersCompanies = new List <SelectListItem>();

            //Create a view model
            JobCreateViewModel viewModel = new JobCreateViewModel();

            //building up the select list
            foreach (Company c in AllCompanies)
            {
                SelectListItem sli = new SelectListItem()
                {
                    //provide text to sli
                    Text = c.Name,
                    //give value to sli
                    Value = c.CompanyId.ToString()
                };
                usersCompanies.Add(sli);
            }
            //Builds a select item "select company" and giving a value of 0
            usersCompanies.Insert(0, new SelectListItem
            {
                Text  = "Select an existing Company",
                Value = ""
            });
            //SelectListItem defaultSli = new SelectListItem
            //{
            // Text = "Select Company",
            //Value = "0"
            //};

            //Sets it at position 0
            // usersCompanies.Insert(0, defaultSli);

            //JobCreateViewModel viewmodel = new JobCreateViewModel
            //{
            //  UsersCompanies = usersCompanies
            //};
            viewModel.UsersCompanies = usersCompanies;


            return(View(viewModel));
        }
Пример #11
0
        private string ProcessUploadedFile(JobCreateViewModel model)
        {
            string uniqueFileName = null;

            if (model.File != null)
            {
                string uploadFileFolder = Path.Combine(hostingEnvironment.WebRootPath, "files");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.File.FileName;
                string filePath = Path.Combine(uploadFileFolder, uniqueFileName);

                using (var filestream = new FileStream(filePath, FileMode.Create))
                {
                    model.File.CopyTo(filestream);
                }
            }
            return(uniqueFileName);
        }
Пример #12
0
        // GET: Jobs/Create
        public async Task <IActionResult> Create()
        {
            var job         = new JobCreateViewModel();
            var jobBenefits = await _jobBenefitsService.GetJobBenefits();

            var jobTypes = await _jobTypesService.GetJobTypes();

            _logger.LogInformation(jobBenefits.Count() + " job benefits found.");

            ViewBag.JobBenefitsList = jobBenefits.Select(x => new SelectListItem {
                Value = x.Id.ToString(), Text = x.Description
            }).ToList();
            ViewBag.JobTypesList = jobTypes.Select(x => new SelectListItem {
                Value = x.Id.ToString(), Text = x.Description
            }).ToList();
            return(View(job));
        }
Пример #13
0
        public IActionResult Create(JobCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = ProcessUploadedFile(model);

                Job newJob = new Job
                {
                    UserID         = userManager.GetUserId(User),
                    Company        = model.Company,
                    JobPosition    = model.JobPosition,
                    JobLink        = model.JobLink,
                    ContactEmail   = model.ContactEmail,
                    ContactName    = model.ContactName,
                    ContactPhone   = model.ContactPhone,
                    AppliedDate    = model.AppliedDate,
                    CloseDate      = model.CloseDate,
                    Expectation    = model.Expectation,
                    AnnualRate     = model.AnnualRate,
                    CommuteCost    = model.CommuteCost,
                    Bonus          = model.Bonus,
                    JobStatus      = 0,
                    NextStep       = JobStatus.Apply,
                    Location       = model.Location,
                    InterviewDate  = model.InterviewDate,
                    InterviewDate2 = null,
                    JobDescription = model.JobDescription,
                    Notes          = null,
                    CoverLetter    = null,
                    Feedback       = null,
                    IsAgency       = model.IsAgency,
                    IsHomeOffice   = model.IsHomeOffice,
                    IsApprentice   = model.IsApprentice,
                    IsPartTime     = model.IsPartTime,
                    FilePath       = uniqueFileName
                };

                _jobRepository.AddJob(newJob);

                newJob.EncryptedId = protector.Protect(newJob.Id.ToString());

                return(RedirectToAction("Details", new { id = newJob.EncryptedId }));
            }
            return(View());
        }
Пример #14
0
        public async Task <IActionResult> Create(JobCreateViewModel job)
        {
            //create new instance of company

            var c = new Company();

            if (_context.Company.Any(com => com.Name == job.Company))
            {
                c = _context.Company.SingleOrDefault(com => com.Name == job.Company);
            }

            else
            {
                c.Name = job.Company;
                _context.Company.Add(c);
                _context.SaveChanges();
            }

            //create new instance of job
            var j = new Job()
            {
                CompanyId = c.Id,
                JobTitle  = job.JobTitle
            };

            _context.Job.Add(j);
            _context.SaveChanges();

            //create new instance of jobnote
            var note = new JobNotes()
            {
                User  = await _userManager.GetUserAsync(User),
                JobId = j.Id,
                Notes = job.Note,
            };

            _context.JobNotes.Add(note);
            _context.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
Пример #15
0
        public async Task <IActionResult> Create([Bind("JobId,Name,Position,DateApplied,StatusId,CompanyId")] Job job)
        {
            ModelState.Remove("ApplicationUserId");
            if (ModelState.IsValid)
            {
                var user = await GetCurrentUserAsync();

                job.ApplicationUser = user;
                _context.Add(job);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.ApplicationUser, "Id", "Id", job.ApplicationUserId);
            ViewData["CompanyId"]         = new SelectList(_context.Company, "CompanyId", "Location", job.CompanyId);
            ViewData["StatusId"]          = new SelectList(_context.Status, "StatusId", "Name", job.StatusId);

            JobCreateViewModel JobCreateViewModel = new JobCreateViewModel(_context);

            return(View(JobCreateViewModel));
        }