public static int Delete(Guid id, bool rollback = false) { try { using (SurveyEntities dc = new SurveyEntities()) { DbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblAnswer deleterow = dc.tblAnswers.FirstOrDefault(a => a.Id == id); if (deleterow != null) { dc.tblAnswers.Remove(deleterow); } else { throw new Exception("Row was not found"); } if (rollback) { transaction.Rollback(); } return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public int Update() { try { using (SurveyEntities dc = new SurveyEntities()) { //If the Id is set, get the result in the table where it matches if (this.Id != Guid.Empty) { tblAnswer answer = dc.tblAnswers.Where(a => a.Id == this.Id).FirstOrDefault(); //If a row was retrieved, change if (answer != null) { answer.Text = this.Text; return(dc.SaveChanges()); } else { throw new Exception("Could not find Answer row with this ID"); } } else { throw new Exception("Id not set on Answer"); } } } catch (Exception ex) { throw ex; } }
public int Insert() { int result = 0; try { using (SurveyEntities dc = new SurveyEntities()) { //Answer new answer and set properties tblAnswer answer = new tblAnswer(); answer.Id = Guid.NewGuid(); answer.Text = this.Text; this.Id = answer.Id; //Add answer to the table dc.tblAnswers.Add(answer); //Commit the changes result = dc.SaveChanges(); return(result); } } catch (Exception ex) { throw ex; } }
public static int Update(Answer answer, bool rollback = false) { try { using (SurveyEntities dc = new SurveyEntities()) { DbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblAnswer updaterow = dc.tblAnswers.FirstOrDefault(a => a.Id == answer.Id); if (updaterow != null) { updaterow.Answer = answer.Text; } else { throw new Exception("Row was not found"); } if (rollback) { transaction.Rollback(); } return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static bool Insert(Answer answer, bool rollback = false) { try { using (SurveyEntities dc = new SurveyEntities()) { DbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblAnswer newrow = new tblAnswer() { Id = Guid.NewGuid(), Answer = answer.Text, }; dc.tblAnswers.Add(newrow); answer.Id = newrow.Id; if (rollback) { transaction.Rollback(); } return(dc.SaveChanges() == 1 ? true : false); } } catch (Exception ex) { throw ex; } }
public void DeleteTest() { using (SurveyEntities dc = new SurveyEntities()) { tblAnswer row = dc.tblAnswers.FirstOrDefault(a => a.Answer == "Sandwhich"); dc.tblAnswers.Remove(row); Assert.AreEqual(1, dc.SaveChanges()); } }
public void UpdateTest() { using (SurveyEntities dc = new SurveyEntities()) { tblAnswer row = dc.tblAnswers.FirstOrDefault(a => a.Answer == "Sandwhich"); if (row != null) { row.Answer = "Hero"; } Assert.AreEqual(1, dc.SaveChanges()); } }
// \AddExperience.aspx // ForumFeed.aspx public void AddForumAnswer(int QID, String Answer, int UserID) { var DC = new DataClassesDataContext(); tblAnswer answer = new tblAnswer(); answer.QuestionID = QID; answer.Answer = Answer; answer.CreatedBy = UserID; answer.CreatedOn = DateTime.Now; DC.tblAnswers.InsertOnSubmit(answer); DC.SubmitChanges(); }
public static void AddNewAnswerRow(TestAnswers context) { var entities = new aeghealthEntities(); var answerdata = new tblAnswer { ConsumerHistoryID = context.ConsumerHistoryId, QuestionID = context.QuestionId, Answer = context.Answer, CreatedByID = context.CreatedById, ModifiedByID = context.ModifiedById }; entities.tblAnswers.Add(answerdata); entities.SaveChanges(); }
public JsonResult SoruKullanici(tblAnswer result) { tblAnswer newAnswer = new tblAnswer { PersonId = result.PersonId, QuestionId = result.QuestionId, Answer = result.Answer, AnswerDate = DateTime.Now }; db.tblAnswer.Add(newAnswer); db.SaveChanges(); return(Json("kaydedildi")); }
public void DeleteTest() { using (SurveyEntities dc = new SurveyEntities()) { tblAnswer answer = dc.tblAnswers.FirstOrDefault(q => q.Text == "UpdatedTestAnswer"); dc.tblAnswers.Remove(answer); dc.SaveChanges(); tblAnswer retrievedAnswer = dc.tblAnswers.FirstOrDefault(q => q.Text == "UpdatedTestAnswer"); Assert.IsNull(retrievedAnswer); } }
public void DeleteTest() { using (SurveyEntities dc = new SurveyEntities()) { //get a question and answer tblAnswer answer = dc.tblAnswers.FirstOrDefault(a => a.Text == "Kelly Kapoor"); tblQuestion question = dc.tblQuestions.FirstOrDefault(q => q.Text == "Who sprouts mung beans in their desk drawers?"); tblQuestionAnswer questionAnswer = dc.tblQuestionAnswers.FirstOrDefault(q => (q.AnswerId == answer.Id) && (q.QuestionId == question.Id)); dc.tblQuestionAnswers.Remove(questionAnswer); int results = dc.SaveChanges(); Assert.IsTrue(results > 0); } }
public int Delete() { try { using (SurveyEntities dc = new SurveyEntities()) { //If the Id is set, get the result in the table where it matches if (this.Id != Guid.Empty) { tblAnswer answer = dc.tblAnswers.Where(a => a.Id == this.Id).FirstOrDefault(); //If a row was retrieved, change if (answer != null) { dc.tblAnswers.Remove(answer); //Make sure to retrieve any rows from the questionAnswerstable with this answerID and delete them as well /*var questionAnswers = dc.tblQuestionAnswers.Where(qa => qa.AnswerId == this.Id); * foreach(tblQuestionAnswer qa in questionAnswers) * { * dc.tblQuestionAnswers.Remove(qa); * } */ //Use stored procedure to retrieve rows from the questionAnswers table with the answerId and delete them dc.spDeleteQAWithAnswer(answer.Id); return(dc.SaveChanges()); } else { throw new Exception("Could not find Answer row with this ID"); } } else { throw new Exception("Id not set on Answer"); } } } catch (Exception ex) { throw ex; } }
public void DeleteTest() { using (SurveyEntities dc = new SurveyEntities()) { //get a question and answer tblAnswer answer = dc.tblAnswers.FirstOrDefault(a => a.Text == "Michael Scott"); tblQuestion question = dc.tblQuestions.FirstOrDefault(r => r.Text == "Who sprouts mung beans in their desk drawers?"); tblResponse response = dc.tblResponses.FirstOrDefault(r => (r.AnswerId == answer.Id) && (r.QuestionId == question.Id)); dc.tblResponses.Remove(response); int results = dc.SaveChanges(); Assert.IsTrue(results > 0); } }
public void InsertTest() { using (SurveyEntities dc = new SurveyEntities()) { tblAnswer answer = new tblAnswer(); answer.Id = Guid.NewGuid(); answer.Text = "TestAnswer"; dc.tblAnswers.Add(answer); dc.SaveChanges(); tblAnswer retrievedAnswer = dc.tblAnswers.FirstOrDefault(q => q.Text == "TestAnswer"); Assert.AreEqual(answer.Id, retrievedAnswer.Id); } }
public static Answer LoadById(Guid id) { try { using (SurveyEntities dc = new SurveyEntities()) { tblAnswer row = dc.tblAnswers.FirstOrDefault(a => a.Id == id); Answer answer = new Answer { Id = row.Id, Text = row.Answer }; return(answer); } } catch (Exception ex) { throw ex; } }
public void InsertTest() { using (SurveyEntities dc = new SurveyEntities()) { //get a question and answer tblAnswer answer = dc.tblAnswers.FirstOrDefault(a => a.Text == "Kelly Kapoor"); tblQuestion question = dc.tblQuestions.FirstOrDefault(r => r.Text == "Who sprouts mung beans in their desk drawers?"); //set properties tblResponse response = new tblResponse(); response.Id = Guid.NewGuid(); response.QuestionId = question.Id; response.AnswerId = answer.Id; dc.tblResponses.Add(response); int results = dc.SaveChanges(); Assert.IsTrue(results > 0); } }