예제 #1
0
        public async Task <IActionResult> Create([FromBody] Subject subject)
        {
            if (String.IsNullOrEmpty(subject.Name))
            {
                return(Ok(new
                {
                    status = ResultStatus.STATUS_INVALID_INPUT,
                    message = "Tên môn học không được để trống"
                }));
            }
            if (subject.LessionSize == default(int))
            {
                return(Ok(new
                {
                    status = ResultStatus.STATUS_INVALID_INPUT,
                    message = "Số tiết học không được để trống"
                }));
            }
            if (subject.Factor == default(int))
            {
                subject.Factor = 1;
            }

            await subjectRepository.Create(subject);

            return(Ok(new
            {
                status = ResultStatus.STATUS_OK,
                data = subject
            }));
        }
예제 #2
0
        private void CreateSubject()
        {
            Regex = new Regex(@"^[a-zA-Z, áéíóöőúüű][a-zA-Z0-9 áéíóöőúüű]{5,19}$");

            if (!Regex.IsMatch(textBoxSubjectName.Text))
            {
                MessageBox.Show("A felhasználónév hossza 6 és 20 karakter közé kell, hogy essen! Csak kis- és nagybetűket, valamint számokat tartalmazhat, és nem kezdődhet számmal!", "Hiba!", MessageBoxButton.OK, MessageBoxImage.Error);

                textBoxSubjectName.Clear();
                return;
            }

            if (!(int.TryParse(textBoxAge.Text, out int age) && (age < 101 && age > 0)))
            {
                MessageBox.Show("Adjon megy egy érvényes életkort!", "Hiba!", MessageBoxButton.OK, MessageBoxImage.Error);
                textBoxAge.Clear();
                return;
            }

            Subject subject = new Subject()
            {
                Nickname         = textBoxSubjectName.Text.Trim(),
                Age              = Convert.ToInt32(textBoxAge.Text.Trim()),
                Gender           = radioButtonMale.IsChecked == true ? Gender.Male : Gender.Female,
                SessionStartDate = DateTime.Now,
                QuestionAnswers  = new List <QuestionAnswer>()
            };

            subjectRepository.Create(subject);
            Finished?.Invoke(this, subject);
        }
예제 #3
0
        public ActionResult Create(SubjectViewModel viewModel)
        {
            var knowledgeAreaRepository = new KnowledgeAreaRepository(_context);

            if (ModelState.IsValid)
            {
                try
                {
                    var knowledgeArea     = knowledgeAreaRepository.GetById(viewModel.KnowledgeAreaId);
                    var subjectRepository = new SubjectRepository(_context);
                    subjectRepository.Create(SubjectViewModel.ToEntity(viewModel, knowledgeArea));
                    _context.Save(_loggedUser);

                    TempData["MessageType"]  = "success";
                    TempData["MessageTitle"] = Resource.ContentManagementToastrTitle;
                    TempData["Message"]      = "Subject created";
                    return(Redirect(TempData["BackURL"].ToString()));
                }
                catch (Exception ex)
                {
                    TempData["MessageType"]  = "error";
                    TempData["MessageTitle"] = Resource.ContentManagementToastrTitle;
                    TempData["Message"]      = ex.Message;
                }
            }


            var knowledgeAreas = knowledgeAreaRepository.ListActiveKnowledgeAreas();

            ViewBag.KnowledgeAreas = new SelectList(knowledgeAreas, "Id", "Name");

            return(View(viewModel));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("ID,TeacherID,Name")] Subject subject)
        {
            if (ModelState.IsValid)
            {
                repository.Create(subject);
                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(subject));
        }
예제 #5
0
        //code to insert into subject repository
        public void Insert(int id)
        {
            int i = 0;

            double[] arrScore = new double[3];
            for (int j = 0; j < 3; j++)
            {
                if (j == 0)
                {
                    Console.WriteLine("Please enter marks for English");
                }
                else if (j == 1)
                {
                    Console.WriteLine("Please enter marks for malayalam");
                }
                else if (j == 2)
                {
                    Console.WriteLine("Please enter marks for Hindi");
                }
                bool boolValue = true;
                while (boolValue)
                {
                    try
                    {
                        arrScore[i] = Convert.ToDouble(Console.ReadLine());
                        boolValue   = false;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Wrong Input");
                        Console.WriteLine("Please reenter the value");
                    }
                }
                i++;
            }

            for (int j = 0; j < 3; j++)
            {
                ArrayList arrayList = new ArrayList()
                {
                    "English  ", "Malayalam", "Hindi    "
                };
                var subject = new Subject()
                {
                    Name = (string)arrayList[j], StudentId = id
                };
                _subjectRepository.Create(subject);
                int Id = subject.Id;
                _markService.Mark(Id, id, j, arrScore);
            }
        }
예제 #6
0
        private void AddSubjectButton_Click(object sender, EventArgs e)
        {
            var subjectRepository = new SubjectRepository();

            var subjectName = addSubjectNameTextBox.Text;
            var subject     = new Subject(subjectName, _universityId);

            if (!SubjectValidation.IsValidSubject(subject))
            {
                return;
            }

            subjectRepository.Create(subject);
            RefreshForm();
        }
예제 #7
0
        private static void Main(string[] args)
        {
            CreateAdminAndCheckLogin();
            AddQuestionsToDb();
            return;

            SubjectRepository subjectRepo = new SubjectRepository();
            Subject           subject     = new Subject()
            {
                Nickname         = "Zoli",
                Age              = 22,
                Gender           = Gender.Female,
                QuestionAnswers  = new List <QuestionAnswer>(),
                SessionStartDate = DateTime.Now
            };

            subjectRepo.Create(subject);

            using QuestionManager questionManager = new QuestionManager();
            Question[] questions = questionManager.GetQuestionsForSubject(subject).ToArray();

            var answers = questions.Select(q => new QuestionAnswer()
            {
                Answer   = true,
                Question = q
            });

            subject.QuestionAnswers.AddRange(answers);
            subjectRepo.SaveChanges();

            Console.WriteLine("FINISHED");
            Console.ReadKey();

            using var context = new QuestionnaireContext();
            context.Questions.RemoveRange(context.Questions);
            context.QuestionAnswers.RemoveRange(context.QuestionAnswers);
            context.Subjects.RemoveRange(context.Subjects);
            context.SaveChanges();
        }
예제 #8
0
        public IActionResult AddCourse(CourseModel courseModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(courseModel));
            }
            Subject subject = subjectRepository.FindByName(courseModel.SubjectName);

            if (subject == null)
            {
                subject      = new Subject();
                subject.Name = courseModel.SubjectName;
                subject      = subjectRepository.Create(subject);
            }
            Course course = new Course();

            course.Name        = courseModel.Name;
            course.Description = courseModel.Description;
            course.AuthorId    = BitConverter.ToInt32(HttpContext.Session.Get("userId"));
            Author author = authorRepository.Read(course.AuthorId);

            course.SubjectId = subject.Id;
            course.Author    = author;
            if (subject.Courses == null)
            {
                subject.Courses = new List <Course>();
            }
            subject.Courses.Add(course);
            if (author.Courses == null)
            {
                author.Courses = new List <Course>();
            }
            author.Courses.Add(course);
            courseRepository.Create(course);
            return(RedirectToAction("Courses", "Course"));
        }
예제 #9
0
 public IActionResult CreateSubject(string id)
 {
     if (string.IsNullOrEmpty(id) == false)
     {
         Subject newSubject = new Subject()
         {
             Name = id
         };
         try
         {
             subjectRopository.Create(newSubject);
             subjectRopository.Save();
         }
         catch (Exception ex)
         {
             return(new JsonResult(new
             {
                 iserror = true,
                 message = "Не удалось сохранить значение",
                 Subject = ""
             }));
         }
         return(new JsonResult(new
         {
             iserror = false,
             message = "",
             Subject = newSubject
         }));
     }
     return(new JsonResult(new
     {
         iserror = true,
         message = "Введите значение",
         Subject = ""
     }));
 }
예제 #10
0
        // POST api/values
        public IHttpActionResult Post([FromBody] Subject subject)
        {
            var new_subject = repo.Create(subject);

            return(new ResponseClass(JsonConvert.SerializeObject(new_subject), Request));
        }
예제 #11
0
        static void Main(string[] args)
        {
            int counter = 1;
            IStudentRepository studentRepository = new StudentRepository();
            ISubjectRepository subjectRepository = new SubjectRepository();

            while (true)
            {
                Console.WriteLine("Enter 1 to add new student\n" +
                                  "Enter 2 to view students list\n" +
                                  "Enter 3 to exit\n" +
                                  "Enter 4 to edit list\n" +
                                  "Enter 5 to add subjects for student\n" +
                                  "Enter 6 to edit subjects\n" +
                                  "Enter 7 to delete subject\n" +
                                  "Enter 8 to view details");
                int switcher = int.Parse(Console.ReadLine());
                switch (switcher)
                {
                case 1:
                    Student student = new Student();
                    student.Id = counter;
                    Console.Write("Enter name: ");
                    student.Name = Console.ReadLine();
                    Console.Write("Enter surname: ");
                    student.Surname = Console.ReadLine();
                    studentRepository.Create(student);
                    counter++;
                    Console.WriteLine($"{student.Name} {student.Surname} has been added");
                    break;

                case 2:
                    if (studentRepository.Count() != 0)
                    {
                        foreach (var st in studentRepository.Get())
                        {
                            Console.Write(st.Id);
                            Console.WriteLine($". {st.Name} {st.Surname} {st.Rating}");
                        }
                    }
                    else
                    {
                        Console.WriteLine("List is empty");
                    }

                    break;

                case 4:
                    Console.Write("Enter ID of a student, who you want to edit: ");
                    int editId = int.Parse(Console.ReadLine());
                    Console.Write("Write new name: ");
                    var name = Console.ReadLine();
                    Console.Write("Write new surname: ");
                    var surname = Console.ReadLine();
                    Console.WriteLine("Student has been successfully edited");
                    studentRepository.Update(editId, name, surname);
                    break;

                case 3:
                    return;

                case 5:
                    Console.WriteLine("Enter ID of a student, whom you want to add subject: ");
                    Subject subject = new Subject();
                    int     addId   = int.Parse(Console.ReadLine());
                    Console.Write("Write name of Subject: ");
                    subject.SubjectName = Console.ReadLine();
                    Console.Write("Write mark of subject: ");
                    subject.Mark = int.Parse(Console.ReadLine());
                    subjectRepository.Create(addId, subject);
                    break;

                case 6:
                    Console.WriteLine("Enter ID of a student, whose subject you want to edit: ");
                    int editSubId = int.Parse(Console.ReadLine());
                    Console.Write("Write name of subject, which you want to edit");
                    string editName = Console.ReadLine();
                    Console.Write("Enter new mark: ");
                    var mark = int.Parse(Console.ReadLine());
                    subjectRepository.Update(editSubId, editName, mark);
                    Console.WriteLine("Subject was successfully edited");
                    break;

                case 7:
                    Console.WriteLine("Enter ID of a student, whose subject you want to delete: ");
                    int deleteId = int.Parse(Console.ReadLine());
                    Console.Write("Write name of subject, which you want to delete");
                    string deleteName = Console.ReadLine();
                    subjectRepository.Delete(deleteId, deleteName);
                    break;

                case 8:
                    Console.WriteLine("Enter ID of a student, who you want to see details: ");
                    int viewId = int.Parse(Console.ReadLine());
                    var st1    = studentRepository.Get(viewId);
                    Console.WriteLine($"ID: {st1.Id}");
                    Console.WriteLine($"Name: {st1.Name}");
                    Console.WriteLine($"Surname: {st1.Surname}");
                    Console.WriteLine($"Rating: {st1.Rating}");
                    Console.WriteLine("Subjects:");
                    foreach (var sub in st1.Subjects)
                    {
                        Console.WriteLine($"\t{sub.SubjectName} {sub.Mark}");
                    }
                    break;

                default:
                    throw new Exception("Wrong numb");
                }
            }
        }