public bool Ekle_ReturnSonID(ExamOfStudent c, out int ID) { using (context = new BasExamContext()) { ID = 0; context.Entry(c).State = EntityState.Added; context.SaveChanges(); ID = c.Id; return(true); } }
public bool Edit(Exam item) { using (context = new BasExamContext()) { context.Entry(item).State = EntityState.Modified; try { result = context.SaveChanges() > 0; } catch (Exception) { result = false; } } return(result); }
public bool Add(Question item) { using (context = new BasExamContext()) { context.Entry(item).State = EntityState.Added; try { result = context.SaveChanges() > 0; } catch { return(result); } } return(result); }
public bool Add(Student item) { using (context = new BasExamContext()) { context.Entry(item).State = EntityState.Added; //context.StudentS.Add(item); try { result = context.SaveChanges() > 0; } catch (Exception) { return(result); } } return(result); }
public bool Delete(int id) { using (context = new BasExamContext()) { Subject trn = context.Subjects.Find(id); context.Entry(trn).State = System.Data.Entity.EntityState.Deleted; try { result = context.SaveChanges() > 0; } catch (Exception) { return(result); } } return(result); }
public bool Delete(int id) { using (context = new BasExamContext()) { Classroom cls = context.Classrooms.Find(id); context.Entry(cls).State = System.Data.Entity.EntityState.Deleted; try { result = context.SaveChanges() > 0; } catch (Exception) { return(result); } } return(result); }
public bool Delete(int id) { Exam exam = null; using (context = new BasExamContext()) { exam = context.Exams.Find(id); context.Entry(exam).State = EntityState.Deleted; try { result = context.SaveChanges() > 0; } catch (Exception) { result = false; } } return(result); }
public bool Delete(int id) { Question question = new Question(); using (context = new BasExamContext()) { question = context.Questions.Find(id); context.Entry(question).State = EntityState.Deleted; try { result = context.SaveChanges() > 0; } catch (Exception) { return(result); } } return(result); }
public ActionResult Add(Exam item, string classroomName, FormCollection fcl) { Classroom cRoom = context.Classrooms.Where(x => x.Name == classroomName).FirstOrDefault(); List <Question> questionList = new List <Question>(); List <ExamQuestion> examQuestionList = new List <ExamQuestion>(); ExamQuestion examQuestion; //int intExamType = Convert.ToInt32(examType); int itemCount = fcl.Count; var keys = Request.Form.AllKeys; //Sınav Ekleme //Öncelikle sınav ekliyoruz daha sonra sınavın konularını ve sorularını ekliyoruz. if (cRoom != null && Session["UserID"] != null) { item.Name = Request.Form.Get(keys[0]); item.ClassroomID = cRoom.Id; //item.Type = Convert.ToInt32(examType); item.TrainerID = (int)Session["UserID"]; item.State = true; //Eklenecek olan sınavın daha önce kaydedilip kaydedilmediğini kontrol eder if (context.Exams.Any(x => x.Name == item.Name && x.ClassroomID == cRoom.Id)) { TempData["msg"] = "Sınav ekleme başarısız!!! " + cRoom.Name + " Sınıfının " + item.Name + "`ı daha önce yapılmıştır"; return(RedirectToAction("Add")); } //Veritabanında istenilen soru adedinin konu bazında yeterli olup olmadığını kontrol eder. for (int i = 2; i < itemCount - 4; i++) { Subject subject = context.Subjects.Find(Convert.ToInt32(keys[i])); int numberOfQuestion = context.Questions.Where(x => x.SubjectID == subject.Id).Count(); if (numberOfQuestion < Convert.ToInt32(Request.Form.Get(keys[i]))) { TempData["msg1"] = "Sınav ekleme başarısız!!! " + subject.Name + " konusunda istediğiniz miktarda soru bulunmamaktadır. Bu konuda veritabanında '" + numberOfQuestion + "' adet soru bulunmaktadır"; return(RedirectToAction("Add")); } } context.Entry(item).State = System.Data.Entity.EntityState.Added; context.SaveChanges(); //List<Student> studentList = context.Students.Where(x => x.ClassroomID == item.ClassroomID) List <Student> studentList = context.Students.Where(x => x.Classrooms.Any(y => y.Id == item.ClassroomID)).ToList(); foreach (Student student in studentList) { ExamOfStudent studentExam = new ExamOfStudent(); studentExam.ExamID = item.Id; studentExam.StudentID = student.Id; studentExam.Score = 0; studentExam.IsActive = true; context.Entry(studentExam).State = System.Data.Entity.EntityState.Added; } } //Sınav için formdan gelen subjectleri sınava ekler for (int i = 2; i < itemCount - 4; i++) { int subID = Convert.ToInt32(keys[i]); Subject sub = context.Subjects.Find(subID); item.Subjects.Add(sub); } //Sınavın sorularını sınava ekler for (int i = 2; i < itemCount - 4; i++) { questionList = GetQuestions(Convert.ToInt32(keys[i]), Convert.ToInt32(Request.Form.Get(keys[i]))); foreach (Question q in questionList) { examQuestion = new ExamQuestion(); examQuestion.QuestionID = q.Id; examQuestion.ClassroomID = cRoom.Id; examQuestion.ExamID = item.Id; examQuestionList.Add(examQuestion); } } foreach (ExamQuestion e in examQuestionList) { context.Entry(e).State = System.Data.Entity.EntityState.Added; } try { if (context.SaveChanges() > 0) { TempData["message"] = true; } } catch { throw; } return(RedirectToAction("Add")); }