public void AddApplicationQualifications(int applicationId, Qualification qualification)
        {
            var application = GetApplication(applicationId, false);

            var applicationQualification = new ApplicationQualification()
            {
                Application   = application,
                Qualification = qualification
            };

            _applicationInfoContext.ApplicationQualifications.Add(applicationQualification);
        }
 public void DeleteApplicationQualificationForApplication(ApplicationQualification applicationQualification)
 {
     _applicationInfoContext.ApplicationQualifications.Remove(applicationQualification);
 }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "ID,Priority,Comment,PostingID,ApplicantID")] Application application, int?id, IEnumerable <HttpPostedFileBase> theFiles, string[] selectedQualification, string[] selectedSkill)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            bool Valid = true;
            var  applicationToCheck = db.Applications.Where(a => a.PostingID == application.PostingID && a.ApplicantID == application.ApplicantID).SingleOrDefault();

            try
            {
                if (selectedQualification != null)                                  // null exception
                {
                    foreach (var q in selectedQualification)                        // loop through each value of the array
                    {
                        var qualificateToAdd = db.Qualification.Find(int.Parse(q)); // receive record from dataset by the id
                        // create new ApplicationQualification Object to add to the ApplicationQualification table
                        ApplicationQualification applicationQualification = new ApplicationQualification
                        {
                            Application     = application,
                            ApplicationID   = application.ID,
                            Qualification   = qualificateToAdd,
                            QualificationID = qualificateToAdd.ID
                        };
                        db.ApplicationQualification.Add(applicationQualification);
                    }
                }
                if (selectedSkill != null)
                {
                    foreach (var s in selectedSkill)
                    {
                        var skillToAdd = db.Skills.Find(int.Parse(s));
                        ApplicationSkill applicationSkill = new ApplicationSkill
                        {
                            Application   = application,
                            ApplicationId = application.ID,
                            Skill         = skillToAdd,
                            skillID       = skillToAdd.ID
                        };
                        db.ApplicationSkills.Add(applicationSkill);
                    }
                }
                if (ModelState.IsValid)
                {
                    AddDocuments(ref application, out Valid, theFiles);

                    if (Valid)
                    {
                        if (applicationToCheck != null)
                        {
                            db.Applications.Remove(applicationToCheck);
                        }


                        db.Applications.Add(application);
                        db.SaveChanges();
                        return(RedirectToAction("Index", "Postings"));
                    }
                    ModelState.AddModelError("", "You only be able to submit PDF or MS Word files.");
                }
            }
            catch (DataException dex)
            {
                ModelState.AddModelError("", "Unable to save changes.");
                if (dex.InnerException.InnerException.Message.Contains("ApplicantID"))
                {
                    return(RedirectToAction("Create", new { UserFlag = true }));
                }
            }


            var posting = (from p in db.Postings
                           where p.ID == id
                           select p).ToList();
            var applicant = db.Applicants.Where(a => a.apEMail == User.Identity.Name).Select(a => a.ID).SingleOrDefault();

            ViewBag.posting     = posting;
            ViewBag.applicantID = applicant;
            ViewBag.postingId   = id;
            return(View(application));
        }