示例#1
0
        public ActionResult Create(CreateJobAdvertViewModel createJobAdvertViewModel)
        {
            var sessionObject = HttpContext.Session;

            //Create validations here
            //var isValidDates = createJobAdvertViewModel.StartDate.CompareTo(createJobAdvertViewModel.EndDate);
            if (createJobAdvertViewModel.SalaryFrom > createJobAdvertViewModel.SalaryTo)
            {
                ModelState.AddModelError("SalaryTo", "Salary From field cannot be greater than Salary To field");
            }


            if (createJobAdvertViewModel.EndDate < createJobAdvertViewModel.StartDate)
            {
                ModelState.AddModelError("StartDate", "Start Date field cannot be greater than End Date field");
            }

            if (createJobAdvertViewModel.RecruiterId.Equals("0") || createJobAdvertViewModel.CompanyId.Equals("0"))
            {
                ModelState.AddModelError("CompanyId", "Select a company and relevant recruiter");
            }

            if (ModelState.IsValid)
            {
                /**
                 * Here its important to check who is creating a job advert because forms are different
                 * for admin and recruiter service for registering is being reused.
                 */
                TempData["AdvertCreate"] = "Advert Successfully Created";
                if (sessionObject.Get <string>("Role").Equals("Admin"))
                {
                    _jobAdvertService.Create(createJobAdvertViewModel);
                }
                else
                {
                    //Get a recruiter from the db so that we have a company ID
                    var recruiter = _recruiterService.Get(sessionObject.Get <string>("RecruiterId"));
                    createJobAdvertViewModel.RecruiterId = recruiter.Id;

                    createJobAdvertViewModel.CompanyId = recruiter.CompanyId;

                    _jobAdvertService.Create(createJobAdvertViewModel);
                }
                //Redirect to success page
                return(View(PrepareJobAdvertModel()));
            }
            else
            {
                return(View(PrepareJobAdvertModel()));
            }
        }
示例#2
0
        private EditRecruiterViewModel PrepareRecruiterEdit(string id)
        {
            var recruiter = _recruiterService.Get(id);

            var editRecruiterViewModel = new EditRecruiterViewModel
            {
                FirstName   = recruiter.FirstName,
                LastName    = recruiter.LastName,
                Companies   = _companyService.GetAll(),
                CompanyId   = recruiter.CompanyId,
                Phone       = recruiter.Phone,
                RecruiterId = id
            };

            return(editRecruiterViewModel);
        }