public List <CharacteristicModel> GetListOfAllCharacteristicsWithTheyAnswers() { List <CharacteristicModel> result = new List <CharacteristicModel>(); try { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { foreach (var characteristic_ in entities.Characteristics) { CharacteristicModel temp = new CharacteristicModel(); temp._text = characteristic_.text; temp.id = characteristic_.id; var answers = entities.Answers_to_the_Characteristics.Where(q => q.characteristic_id == characteristic_.id); foreach (var item in answers) { temp.answers_to_characteristic.Add(new AnswerToCharacteristicModel() { Text = item.text, CharacteristicId = characteristic_.id }); } result.Add(temp); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(result); }
public Characteristics SelectCharacteristic(int id) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { return(entities.Characteristics.Find(id)); } }
public CharacteristicModel GetAllCharacteristicAnswers() { CharacteristicModel result = new CharacteristicModel(); try { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { var characteristic = entities.Characteristics.FirstOrDefault(); result._text = characteristic.text; result.id = characteristic.id; var answers = entities.Answers_to_the_Characteristics.Where(q => q.characteristic_id == characteristic.id); foreach (var item in answers) { result.answers_to_characteristic.Add(new AnswerToCharacteristicModel() { Text = item.text, CharacteristicId = characteristic.id }); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(result); }
public Answers_to_the_Characteristics SelectAnswerToCharacteristic(int id) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { return(entities.Answers_to_the_Characteristics.Find(id)); } }
public void SelectAnswerToTheQuestions(int id) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { var answerToSelect = entities.Answers_to_the_Questions.Find(id); } }
public void UpdateAnswerToTheQuestions(int id, String text) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { var answerToUpdate = entities.Answers_to_the_Questions.Find(id); answerToUpdate.text = text; entities.SaveChanges(); } }
public void UpdateCharacteristic(int id, String text) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { var characteristicToUpdate = entities.Characteristics.Find(id); characteristicToUpdate.text = text; entities.SaveChanges(); } }
public void DeleteAnswer(int CustomerId) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { var Answer = entities.Answering_the_Question.Find(CustomerId); entities.Answering_the_Question.Remove(Answer); entities.SaveChanges(); } }
public void DeleteAnswerToCharacteristic(int id) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { var answerToDelete = entities.Answers_to_the_Characteristics.Find(id); entities.Answers_to_the_Characteristics.Remove(answerToDelete); entities.SaveChanges(); } }
public void DeleteAnswerToTheQuestions(int id) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { var answerToDelete = entities.Answers_to_the_Questions.Find(id); entities.Answers_to_the_Questions.Remove(answerToDelete); entities.SaveChanges(); } }
public void DeleteCharacteristic(int id) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { var characteristicToDelete = entities.Characteristics.Find(id); entities.Characteristics.Remove(characteristicToDelete); entities.SaveChanges(); } }
public void UpdateAnswerToCharacteristic(int id, String text, int char_id) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { var answerToUpdate = entities.Answers_to_the_Characteristics.Find(id); answerToUpdate.text = text; answerToUpdate.characteristic_id = char_id; entities.SaveChanges(); } }
public AnswerModel SelectAnswerToTheQuestions(int id) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { Answers_to_the_Questions answer = entities.Answers_to_the_Questions.Find(id); AnswerModel ans = new AnswerModel(answer.text); return(ans); } }
public void CreateAnswerToTheQuestions(String txt, int question_id) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { entities.Answers_to_the_Questions.Add(new Answers_to_the_Questions() { text = txt, question_id = question_id }); entities.SaveChanges(); } }
public void CreateCharacteristic(String txt) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { entities.Characteristics.Add(new Characteristics() { text = txt }); entities.SaveChanges(); } }
public void CreateAnswerToTheQuestions(int q_id, String text) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { entities.Answers_to_the_Questions.Add(new Answers_to_the_Questions() { question_id = q_id, text = text, type = 1 }); entities.SaveChanges(); } }
public void CreateAnswerToCharacteristic(String txt, int char_id) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { entities.Answers_to_the_Characteristics .Add(new Answers_to_the_Characteristics() { text = txt, characteristic_id = char_id }); entities.SaveChanges(); } }
public void CreateAnswer(int Question_id, int Question_answer_id, int Characteristic_id, int Characteristics_answers_id) { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { entities.Answering_the_Question.Add( new Answering_the_Question() { question_id = Question_id , question_answer_id = Question_answer_id , characteristic_id = Characteristic_id , characteristic_answers_id = Characteristics_answers_id }); entities.SaveChanges(); } }
public int GetMaxId() { int id = 0; using (OfficePoll2Entities entities = new OfficePoll2Entities()) { try { id = entities.Questions.Max(q => q.id); } catch (Exception) { id = 0; } } return(id); }
public ParentModel GetQuestionOfTheDay() { ParentModel result = new ParentModel(initializeQuestions: false); try { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { var questionOfTheDay = entities.Questions.FirstOrDefault(q => q.date == DateTime.Today); //System.Diagnostics.Debug.WriteLine(DateTime.Today); //var question = questions.First(); if (questionOfTheDay != null) { result.Question.Question = questionOfTheDay.text; result.Question.id = questionOfTheDay.id; result.Question.Date = questionOfTheDay.date.ToShortDateString(); // to format var answers = entities.Answers_to_the_Questions.Where(a => a.question_id == questionOfTheDay.id); foreach (var item in answers) { result.AnswersCollection.Add(new AnswerModel() { QuestionId = item.question_id, Text = item.text }); } } else { throw new MissingMemberException("There isn't question of the day!"); } } } catch (MissingMemberException missing) { if (missing.Message.Equals("There isn't question of the day!")) { throw missing; } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(result); }
public void DeleteQuestion(int id) { try { using (OfficePoll2Entities entities = new OfficePoll2Entities()) { var question = entities.Questions.Find(id); IQueryable <Answers_to_the_Questions> answers = entities.Answers_to_the_Questions.Where(item => item.question_id == question.id); foreach (var a in answers) { var ans = entities.Answers_to_the_Questions.Find(a.id); entities.Answers_to_the_Questions.Remove(ans); } entities.Questions.Remove(question); entities.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }