public ActionResult Edit(Vacancy vacancy)
 {
     Vacancy VacancyEdit = _ContextDataVacancy.Get<Vacancy>(vacancy.Id);
     TryUpdateModel(VacancyEdit);
     _ContextDataVacancy.SaveChanges( );
     return RedirectToAction("Sucess", "Home");
 }
        public ActionResult Delete(Vacancy vacancy)
        {
            Vacancy VacancyDelete = _ContextDataVacancy.Get<Vacancy>(vacancy.Id);

            _ContextDataVacancy.Delete<Vacancy>(VacancyDelete);
            _ContextDataVacancy.SaveChanges( );
            return RedirectToAction("Sucess", "Home");
        }
        public ActionResult Create(Vacancy vacancy)
        {
            if (ModelState.IsValid)
            {
                _ContextDataVacancy.Add<Vacancy>(vacancy);
                _ContextDataVacancy.SaveChanges( );

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

            return View( );
        }
        public ActionResult Create(Vacancy vacancy)
        {
            vacancy.RegistrionDate = DateTime.Now;
            ModelState["ProfileVacancy.Myprofile"].Errors.Clear( );
            ModelState["Status"].Errors.Clear( );

            string CompanyName = User.Identity.Name;

            if (ModelState.IsValid)
            {

                if (vacancy.RegistrationDeadline > DateTime.Now.Date)
                {
                    ModelState.AddModelError("", "A data deve ser maior que a data atual.");
                }
                vacancy.Benefits = vacancy.Benefits;
                vacancy.Description = vacancy.Description;
                vacancy.KeyWords = RemoveString.GenerateKeyWords(vacancy.Description);
                vacancy.OfficeHours = vacancy.OfficeHours;
                vacancy.ProfileVacancy = _ContextDataVacancy.Get<ProfileVacancy>(vacancy.ProfileVacancy.Id);
                vacancy.Status = _ContextDataVacancy.GetAll<Status>( ).Where(x => x.Description == "Aberto").First( );
                vacancy.CompanyName = _ContextDataVacancy.GetAll<Company>( )
                                      .Where(x => x.Name == CompanyName).First( );
                string Body = " Encontra-se disponível uma vaga na empresa:" + CompanyName + "\n<br/>" +
                              "Com a seguinte descrição : " + vacancy.Description + "\n<br/>" +
                              "Benefícios: " + vacancy.Benefits + "\n<br/>" +
                              "Números de Vagas: " + vacancy.JobsNumber + "\n<br/>" +
                              "Data de inscrição: " + " de: " + DateTime.Now.Date + " Até: " + vacancy.RegistrationDeadline.Date + "\n<br/>" +
                               "Para Visualizar a Vaga Clique <a href='http://localhost:1677/CommonUser/Vacancy/ListVacancyOpen'>Aqui</a>";

                _ContextDataVacancy.Add<Vacancy>(vacancy);

                _ContextDataVacancy.SaveChanges( );

                IList<Profile> ListMail = _ContextDataVacancy.GetAll<Profile>( ).ToList( );
                foreach (var item in ListMail)
                {
                    if (item.EmailAddress != null)
                    {
                        WebMail.Send(item.EmailAddress, "Vaga disponível na empresa : " + CompanyName, item.FirstName + Body);

                    }
                }

                return RedirectToAction("Sucess", "Home");

            }
            ViewBag.PerfilVaga = new SelectList(_ContextDataVacancy.GetAll<ProfileVacancy>( ), "Id", "Myprofile", vacancy.ProfileVacancy);
            ViewBag.StatusVaga = new SelectList(_ContextDataVacancy.GetAll<Status>( ), "Code", "Description", vacancy.Status);

            return View( );
        }
        public ActionResult Create(Vacancy vacancy)
        {
            vacancy.RegistrionDate = DateTime.Now;
            ModelState["ProfileVacancy.Myprofile"].Errors.Clear( );
            ModelState["CompanyName.Name"].Errors.Clear( );
            ModelState["CompanyName.Email"].Errors.Clear( );
            ModelState["Status"].Errors.Clear( );

            if (ModelState.IsValid)
            {

                if (vacancy.RegistrationDeadline.Date <= DateTime.Now.Date)
                {
                    ModelState.AddModelError("", "A data deve ser maior que a data atual.");
                }
                vacancy.Benefits = vacancy.Benefits.ToLower();
                vacancy.Description = vacancy.Description.ToLower();
                vacancy.OfficeHours = vacancy.OfficeHours.ToLower();
                vacancy.ProfileVacancy = _ContextDataVacancy.Get<ProfileVacancy>(vacancy.ProfileVacancy.Id);
                vacancy.CompanyName = _ContextDataVacancy.Get<Company>(vacancy.CompanyName.Id);
                vacancy.Status = _ContextDataVacancy.GetAll<Status>( ).Where(x => x.Description == "Aberto").First( );
                vacancy.KeyWords = RemoveString.GenerateKeyWords(vacancy.Description);

                if (vacancy.Status == null)
                {
                    ModelState.AddModelError("", "O Status não pode ser vazio.");
                }
                _ContextDataVacancy.Add<Vacancy>(vacancy);

                _ContextDataVacancy.SaveChanges( );

                return RedirectToAction("Sucess", "Home");

            }

            ViewBag.PerfilVaga = new SelectList(_ContextDataVacancy.GetAll<ProfileVacancy>( ), "Id", "Myprofile", vacancy.ProfileVacancy.Id);
            ViewBag.StatusVaga = new SelectList(_ContextDataVacancy.GetAll<Status>( ), "Code", "Description", vacancy.Status.Code);
            ViewBag.Company = new SelectList(_ContextDataVacancy.GetAll<Company>( ), "Id", "Name", vacancy.CompanyName.Id);

            return View( );
        }
        public ActionResult Delete(Vacancy vacancy)
        {
            Vacancy VacancyDelete = _ContextDataVacancy.Get<Vacancy>(vacancy.Id);
            IList<JobCandidate> CandidateList = _ContextDataVacancy.GetAll<JobCandidate>( )
                                                .Where(x => x.JobCandidato.Id == vacancy.Id).ToList( );
            if (CandidateList.Count( ) >= 1)
            {
                return RedirectToAction("UsersJobs", "Vacancy");
            }

            _ContextDataVacancy.Delete<Vacancy>(VacancyDelete);
            _ContextDataVacancy.SaveChanges( );
            return RedirectToAction("Sucess", "Home");
        }
 public ActionResult Edit(Vacancy vacancy)
 {
     Vacancy VacancyEdit = _ContextDataVacancy.Get<Vacancy>(vacancy.Id);
     VacancyEdit.OfficeHours = vacancy.OfficeHours.ToLower( );
     VacancyEdit.Description = vacancy.Description.ToLower( );
     VacancyEdit.Benefits = vacancy.Benefits.ToLower( );
     VacancyEdit.KeyWords = RemoveString.GenerateKeyWords(vacancy.Description);
     TryUpdateModel(VacancyEdit);
     _ContextDataVacancy.SaveChanges( );
     return RedirectToAction("ListVacancyDetails", "Vacancy");
 }