Пример #1
0
        public int AddCategory(string name)
        {
            Category category = new Category()
            {
                Name      = name,
                TeacherId = 1
            };

            context.Categories.Add(category);
            context.SaveChanges();
            int id = context.Categories.FirstOrDefault(x => x.Name == name).Id;

            return(id);
        }
Пример #2
0
        /// <summary>
        /// Vendég regisztrációja.
        /// </summary>
        /// <param name="guest">A vendég nézetmodellje.</param>
        public Boolean Register(RegistrationViewModel guest)
        {
            if (guest == null)
            {
                return(false);
            }

            // ellenőrizzük az annotációkat
            if (!Validator.TryValidateObject(guest, new ValidationContext(guest, null, null), null))
            {
                return(false);
            }

            //Fixme: StudentName would be StudentUser.
            if (_context.Student.Count(c => c.StudentName == guest.UserName) != 0)
            {
                return(false);
            }

            // kódoljuk a jelszót
            Byte[] passwordBytes = null;
            using (SHA512CryptoServiceProvider provider = new SHA512CryptoServiceProvider())
            {
                passwordBytes = provider.ComputeHash(Encoding.UTF8.GetBytes(guest.UserPassword));
            }


            // elmentjük a felhasználó adatait
            _context.Student.Add(new Student
            {
                StudentName = guest.UserName,
                //Password = System.Text.Encoding.UTF8.GetString(passwordBytes),
                Password = guest.UserPassword,
            });

            try
            {
                _context.SaveChanges();
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Пример #3
0
        public void AddNewUserParent(string nameMather, string surnameMather, string PatrMathe, string nameFather, string surnameFather, string PatrFather, string phoneMathe, string phoneFather, string email, string password, int code)// добавление нового пользователя родитель
        {
            Parents tmp = new Parents();

            using (EducationSystemContext esc = new EducationSystemContext())
            {
                tmp.NameMather       = nameMather;
                tmp.SurnameFather    = surnameMather;
                tmp.PatronymicMather = PatrMathe;
                tmp.NameFather       = nameFather;
                tmp.SurnameFather    = surnameFather;
                tmp.PatronymicFather = PatrFather;
                tmp.PhoneFather      = phoneFather;
                tmp.PhoneMathe       = phoneMathe;
                tmp.Email            = email;
                tmp.Password         = password;
                esc.Parents.Add(tmp);
                esc.SaveChanges();
                esc.Database.ExecuteSqlRaw("UPDATE [Pupils] Set [IDParent]={0} where [IDPupil]={0}", tmp.Idparent, code);
                esc.SaveChanges();
            }
        }
Пример #4
0
        public ActionResult Create(FormCollection form)
        {
            string   name      = form["name"];
            int      teacherId = GetTeacherID();
            Category category  = new Category()
            {
                Name = name, TeacherId = teacherId
            };

            context.Categories.Add(category);
            context.SaveChanges();
            ToastrService.AddToUserQueue(new Toastr("Kategori Eklendi", null, ToastrType.Success));
            return(RedirectToAction("Create", "Question"));
        }
Пример #5
0
        public void AddNewUserTeacher(string name, string surnam, string patr, string phone, int?idschool, int?idsubject, string email, string password)  // добавление нового пользователя учитель
        {
            Teachers tmp = new Teachers();

            using (EducationSystemContext esc = new EducationSystemContext())
            {
                tmp.Name       = name;
                tmp.Surname    = surnam;
                tmp.Patronymic = patr;
                tmp.Phone      = phone;
                tmp.Idschool   = idschool;
                tmp.Idsubject  = idsubject;
                tmp.Email      = email;
                tmp.Password   = password;
                esc.Teachers.Add(tmp);
                esc.SaveChanges();
            }
        }
Пример #6
0
        public void AddNewUserPupil(string name, string surnam, string patr, string phone, int?idschool, string email, string password, int number) // добавление нового пользователя ученик
        {
            Pupils tmp = new Pupils();

            using (EducationSystemContext esc = new EducationSystemContext())
            {
                tmp.Name        = name;
                tmp.Surname     = surnam;
                tmp.Patronymic  = patr;
                tmp.Phone       = phone;
                tmp.Idschool    = idschool;
                tmp.NamberClass = number;
                tmp.Email       = email;
                tmp.Password    = password;
                tmp.Code        = 1000;
                esc.Pupils.Add(tmp);
                esc.SaveChanges();
            }
        }
        public ActionResult TakeTheExam(FormCollection form)
        {
            int trueCounter  = 0;
            int falseCounter = 0;

            Exam exam = new Exam {
                StudentId = Convert.ToInt32(Session["StudentId"]), Date = DateTime.Now
            };

            List <ExamCategory> examCategories = new List <ExamCategory>();

            foreach (var item in _questionsIdList)
            {
                if (form[item.Key.ToString()] == null)
                {
                    continue;
                }

                string result   = form[item.Key.ToString()];
                string dbAnswer = GetRightAnswer(item.Key);

                bool isNewCategory = true;
                foreach (ExamCategory examCategory in examCategories.Where(examCategory => examCategory.CategoryId == item.Value))
                {
                    isNewCategory = false;
                    if (result == dbAnswer)
                    {
                        examCategory.TrueCounter += 1;
                        trueCounter += 1;
                    }
                    else
                    {
                        examCategory.FalseCounter += 1;
                        falseCounter += 1;
                    }
                }

                if (!isNewCategory)
                {
                    continue;
                }

                ExamCategory newExamCategory = new ExamCategory {
                    CategoryId = item.Value, TrueCounter = 0, FalseCounter = 0
                };

                examCategories.Add(newExamCategory);

                if (result == dbAnswer)
                {
                    newExamCategory.TrueCounter += 1;
                    trueCounter += 1;
                }
                else
                {
                    newExamCategory.FalseCounter += 1;
                    falseCounter += 1;
                }
            }

            exam.TrueCounter  = trueCounter;
            exam.FalseCounter = falseCounter;
            exam.Point        = trueCounter * 2;

            _context.Exams.Add(exam);
            _context.SaveChanges();

            foreach (var examCategory in examCategories)
            {
                int examId = exam.Id;
                examCategory.ExamId = examId;
                _context.ExamCategories.Add(examCategory);
            }

            List <PerformanceCategory> performanceCategories = new List <PerformanceCategory>();

            foreach (var examCategory in examCategories)
            {
                bool isExist = IsCategoryInList(performanceCategories, examCategory);

                if (isExist)
                {
                    continue;
                }

                PerformanceCategory newPerformanceCategory = new PerformanceCategory
                {
                    CategoryId   = examCategory.CategoryId,
                    TrueCounter  = examCategory.TrueCounter,
                    FalseCounter = examCategory.FalseCounter,
                    StudentID    = GetStundetId()
                };

                performanceCategories.Add(newPerformanceCategory);
            }

            foreach (PerformanceCategory performanceCategory in performanceCategories)
            {
                PerformanceCategory performCategory =
                    GetPerformanceWithCategoryId(GetStundetId(), performanceCategory.CategoryId);

                if (performCategory != null)
                {
                    performCategory.TrueCounter  += performanceCategory.TrueCounter;
                    performCategory.FalseCounter += performanceCategory.FalseCounter;
                }
                else
                {
                    AddPerformanceCategory(performanceCategory);
                }
            }

            _context.SaveChanges();

            List <Category> categories = GetTeacherCategories(GetTeacherIDForStudent());

            List <PerformanceCategory> existPerformanceCategories = GetPerformanceCategoriesForStudent(GetStundetId());

            foreach (var category in categories)
            {
                bool isExist = false;
                foreach (var performanceCategory in existPerformanceCategories)
                {
                    if (category.Id == performanceCategory.CategoryId)
                    {
                        isExist = true;
                        break;
                    }
                }

                if (isExist)
                {
                    continue;
                }

                var newPerformanceCategory = new PerformanceCategory
                {
                    CategoryId   = category.Id,
                    TrueCounter  = 0,
                    FalseCounter = 0,
                    StudentID    = GetStundetId()
                };

                AddPerformanceCategory(newPerformanceCategory);
            }

            _context.SaveChanges();
            ToastrService.AddToUserQueue("", "Sınavınız tamamlandı!", ToastrType.Info);
            return(RedirectToAction("Index", "Student"));
        }
Пример #8
0
        public ActionResult Create(FormCollection form)
        {
            string base64Str = "";

            try
            {
                if (Request != null)
                {
                    var image = Request.Files[0];
                    if (image.ContentLength > 0)
                    {
                        var picture = Image.FromStream(image.InputStream);
                        base64Str = ImageToBase64(picture);
                        if (base64Str.ToString().Length > 47999)
                        {
                            ToastrService.AddToUserQueue(new Toastr("Bir Hata Oluştu", "Düşük Kaliteli Fotoğraf Seçiniz", ToastrType.Error));
                            return(RedirectToAction("Index"));
                        }
                    }
                }
            }
            catch (Exception)
            {
                ToastrService.AddToUserQueue(new Toastr("Bir Hata Oluştu", "Resim seçtiğinize emin olunuz !", ToastrType.Error));
                return(View());
            }



            string title       = form["title"];
            string file        = base64Str;
            string answer      = form["answer"];
            string categoryId  = form["Categories"];
            string choiceOne   = form["choiceOne"];
            string choiceTwo   = form["choiceTwo"];
            string choiceThree = form["choiceThree"];
            string choiceFour  = form["choiceFour"];
            int    teacherId   = GetTeacherID();



            Question question = new Question()
            {
                Title       = title,
                Picture     = file,
                Answer      = answer,
                CategoryId  = Convert.ToInt32(categoryId),
                AddedTime   = DateTime.Now,
                ChoiceOne   = choiceOne,
                ChoiceTwo   = choiceTwo,
                ChoiceThree = choiceThree,
                ChoiceFour  = choiceFour,
                TeacherId   = teacherId
            };

            context.Questions.Add(question);
            context.SaveChanges();

            ToastrService.AddToUserQueue(new Toastr("Soru Eklendi", null, ToastrType.Success));
            return(RedirectToAction("Index"));
        }