Exemplo n.º 1
0
        public JsonResult PostScore(int score, string comment, string submitID)
        {
            AssessmentDAO assDao = new AssessmentDAO();

            if (assDao.AddOrUpdate(score, comment, submitID))
            {
                return(Json(new { success = true }));
            }
            return(Json(new { success = false }));
        }
Exemplo n.º 2
0
        public bool PostAssessment(AssessmentDAO assessment)
        {
            AssessmentServiceClient client = new AssessmentServiceClient();

            try
            {
                bool result = client.CreateAssessment(assessment);
                return result;
            }
            catch (FaultException<KaskServiceException> e)
            {
                throw new HttpException(e.Message);
            }
        }
Exemplo n.º 3
0
        public async Task<ActionResult> Create(FormCollection collection)
        {
            try
            {
                if (Request.Form["acknowledgeAccurateDataCheckbox"] != null)
                {
                    // save application form data back to database through service
                    using (HttpClient httpClient = new HttpClient())
                    {
                        httpClient.BaseAddress = new Uri("http://localhost:51309");
                        httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                        HttpResponseMessage result = new HttpResponseMessage();
                        string resultContent = "";

                        // find applicant id from the previously submitted Application form, if available
                        int applicantID = 0;
                        if (Convert.ToInt32(Request.Form["applicantID"]) > 0)
                        {
                            applicantID = Convert.ToInt32(Request.Form["applicantID"]);
                        }
                        // otherwise, get last applicant id from database
                        else
                        {
                            var applieds = await ServerResponse<List<AppliedDAO>>.GetResponseAsync(ServiceURIs.ServiceAppliedUri);
                            applicantID = applieds.Last().ApplicantID;
                        }

                        // gather AssessmentOpening form data
                        AssessmentDAO assessment = new AssessmentDAO();
                        assessment.ApplicantID = applicantID;

                        // and save the mc answer chosen by applicant

                        // first, parse the questionBankId and optionId of checkbox chosen by user

                        int parsedQuestionBankId = 0;
                        int parsedQuestionId = 0;
                        int parsedOptionId = 0;

                        var questionBankAnswers = await ServerResponse<List<QuestionBankDAO>>.GetResponseAsync(ServiceURIs.ServiceQuestionBankUri);

                        // TODO: change the hardcoded "50" into some sort of variable
                        // (i.e. the length of all possible questionBank ids, questions, and options)
                        for (int i = 0; i < 50; i++)
                        {
                            for (int j = 0; j < 50; j++)
                            {
                                for (int k = 0; k < 50; k++)
                                {
                                    try
                                    {
                                        if (Request.Form["MCOption_" + i + "_" + j + "_" + k] != null)
                                        {
                                            parsedQuestionBankId = i;
                                            parsedQuestionId = j;
                                            parsedOptionId = k;

                                            // check to see if answer is valid or "correct"
                                            // if not valid, redirect to "sorry" screen
                                            foreach (QuestionBankDAO qbItem in questionBankAnswers)
                                            {
                                                if (qbItem.QuestionBankID.Equals(parsedQuestionBankId))
                                                {
                                                    if (!parsedOptionId.Equals(Convert.ToInt32(qbItem.MCCorrectOption)))
                                                    {
                                                        // delete failed application
                                                        var applications = await ServerResponse<List<ApplicationDAO>>.GetResponseAsync(ServiceURIs.ServiceApplicationUri);
                                                        int applicationID = applications.Last().ApplicationID;

                                                        var resultTwo = await httpClient.DeleteAsync(ServiceURIs.ServiceApplicationUri.ToString() + "/" + applicationID.ToString());

                                                        // delete failed applicant
                                                        resultTwo = await httpClient.DeleteAsync(ServiceURIs.ServiceApplicantUri.ToString() + "/" + applicantID.ToString());

                                                        // delete failed applied
                                                        resultTwo = await httpClient.DeleteAsync(ServiceURIs.ServiceAppliedUri.ToString() + "/" + applicantID.ToString());

                                                        return RedirectToAction("Sorry");
                                                    }
                                                    else
                                                    {
                                                        // this is the answer that the user chose for this particular QuestionBank question
                                                        assessment.QuestionBankID = parsedQuestionBankId;

                                                        // post (save) AssessmentOpening data
                                                        result = httpClient.PostAsJsonAsync(ServiceURIs.ServiceAssessmentUri, assessment).Result;
                                                        resultContent = result.Content.ReadAsStringAsync().Result;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    catch { }
                                }
                            }
                        }

                        
                    }

                    // redirect to phone interview questions, if possible
                    return RedirectToAction("Create", "Interviews", new { ID = Convert.ToInt32(Request.Form["JobOpeningIDReferenceNumberOnAssessment"]) });
                }
                else
                {
                    // TODO: validation later on...
                    return RedirectToAction("Create");
                }
            }
            catch
            {
                // TODO: validation later on...
                return RedirectToAction("Create");
            }
        }