Exemplo n.º 1
0
 public IActionResult Form(Result result)
 {
     if (ModelState.IsValid)
     {
         Result newResult = _resultRepository.Add(result);
         return(RedirectToAction("resultSheet", new { Id = newResult.Id }));
     }
     return(View());
 }
Exemplo n.º 2
0
        public IActionResult TakeExam(TakeExamViewModel giveExamViewModel)
        {
            var questions = examQuestionRepository.GetExamQuestions(giveExamViewModel.ExamId).Select(c => c.Question).Select(c => c.QuestionChoices.Select(v => v.Choice.IsCorrect)).ToList();
            int score     = 0;
            var user      = userManager.GetUserId(User);

            try
            {
                foreach (var item in giveExamViewModel.Answers)
                {
                    Answer answer = new Answer
                    {
                        AppUserId  = int.Parse(user),
                        ChoiceId   = item.ChoiceId,
                        IsSelected = item.IsSelected
                    };
                    answerRepository.Add(answer);
                    var choice = choiceRepository.Get(item.ChoiceId);
                    if (item.IsSelected == true && choice.IsCorrect == true)
                    {
                        score++;
                    }
                }
            }
            catch
            {
                return(NotFound());
            }

            double resultScore = Math.Round((((double)score / (double)questions.Count) * 100), 2);

            Result result = new Result
            {
                AppUserId = int.Parse(user),
                ExamId    = giveExamViewModel.ExamId,
                Score     = resultScore,
                Exam      = examRepository.Get(giveExamViewModel.ExamId),
                dateTime  = DateTime.Now
            };

            resultRepository.Add(result);
            return(RedirectToAction("FinishExam", new { ResultId = result.Id }));
        }
Exemplo n.º 3
0
 public void AddItem(Restaurantes item)
 {
     _repository.Add(item);
 }
Exemplo n.º 4
0
        public List <Photo> ApiHandler(string uri, int id)
        {
            var    outputList = new List <Photo>();
            string str;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(uri);
                Dictionary <string, string> pairs = new Dictionary <string, string>();
                pairs.Add("crawlid", id.ToString());
                FormUrlEncodedContent formContent =
                    new FormUrlEncodedContent(pairs);

                var responseTask = client.PostAsync(client.BaseAddress, formContent);
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readJob = result.Content.ReadAsStringAsync();
                    readJob.Wait();
                    str = readJob.Result;
                    if (JObject.Parse(str)["image_count"].Equals("0"))
                    {
                        return(outputList);
                    }
                    var engine = JObject.Parse(str)["spider"];
                    str = JObject.Parse(str)["images"].ToString();

                    var list = JsonConvert.DeserializeObject <List <Photo> >(str);

                    Result res;
                    foreach (var photo in list)
                    {
                        photo.ID = 0;
                        Photo returnedPhoto;
                        var   control = _photoRepository.FindPhoto(photo.Url);
                        if (control == null)
                        {
                            returnedPhoto = _photoRepository.Add(photo);
                        }
                        else
                        {
                            returnedPhoto = control;
                        }
                        outputList.Add(returnedPhoto);
                        res = new Result
                        {
                            PhotoId  = returnedPhoto.ID,
                            EngineId = engine.Equals("GoogleImages") ? 1 : 2,
                            SearchId = id
                        };
                        _resultRepository.Add(res);
                    }
                }
                else
                {
                }

                return(outputList);
            }
        }