public bool AddAnswerByTest(int testId, int postionId) { var answers = new List <Answer>(); var candidats = _candidatRepositories.GetCandidats(postionId); foreach (var can in candidats) { var ans = new AnswerDto { CandidatId = can.Id, TestId = testId, Reference = _answerRepository.FindGuidByCandidat(can.Id) }; answers.Add(GetModel(ans)); } var res = _answerRepository.AddRange(answers); return(res); }
public bool SetTemplateQuestion(TemplateTabQuesionModel model) { try { var tempQuestion = new TemplateQue(); if (model.TemplateQuesID > 0) { tempQuestion = _templateQuestionRepository.GetById(model.TemplateQuesID); tempQuestion.TemplateTabID = model.TemplateTabID; tempQuestion.Question = model.Question; tempQuestion.Section = model.Section; tempQuestion.AnswerDetails = model.AnswerDetails; tempQuestion.AnswerType = model.AnswerType; tempQuestion.ParentId = model.Parent; tempQuestion.RenderOnAnwerId = model.RenderOnAnswerId; tempQuestion.Tooltip = model.Tooltip; tempQuestion.ModifiedOn = DateTime.UtcNow; tempQuestion.ModifiedBy = 1; _templateQuestionRepository.Update(tempQuestion); } else { tempQuestion.TemplateQuesID = model.TemplateTabID; tempQuestion.TemplateTabID = model.TemplateTabID; tempQuestion.Section = model.Section; tempQuestion.Question = model.Question; tempQuestion.AnswerDetails = model.AnswerDetails; tempQuestion.AnswerType = model.AnswerType; tempQuestion.ParentId = model.Parent; tempQuestion.RenderOnAnwerId = model.RenderOnAnswerId; tempQuestion.Tooltip = model.Tooltip; tempQuestion.CreatedOn = DateTime.Now; tempQuestion.CreatedBy = 1; _templateQuestionRepository.Add(tempQuestion); if (!string.IsNullOrWhiteSpace(model.AnswerDetails)) { var answers = (from ans in model.AnswerDetails.Split(',') select new Answer { AnswerText = ans, QuestionId = tempQuestion.TemplateQuesID }).ToList(); _answerRepository.AddRange(answers); } } //_templateQuestionRepository.SaveChangesAsync(); return(true); } catch (EntryPointNotFoundException ex) { return(false); } catch (Exception ex) { return(false); } }