Exemple #1
0
        //repository to edit the student details
        public void Update(int studentId)
        {
            var getStudent  = _studentRepository.StudentDetails(studentId);
            var studentList = _studentRepository.GetStudentDetails(studentId);
            var groupByName = studentList.GroupBy(i => i.Id).Select(y => new
            {
                Key   = y.Key,
                Value = y.ToList()
            }).ToList();

            foreach (var p in groupByName)
            {
                Console.WriteLine("\nStudent ID : {0}    Name : {1}    Age  : {2}\n", p.Key, p.Value[0].Name, p.Value[0].Age);
                p.Value.ForEach(i => Console.WriteLine("{0}  \t\t {1}\t ", i.Subject, i.Mark));
            }
            Console.WriteLine("Press 1 to change personal details and 2 to change subject details");
            var dataValue = Convert.ToInt32(Console.ReadLine());

            if (dataValue == 1)
            {
                try
                {
                    Console.WriteLine(Message.edit1);
                    Console.WriteLine(Message.changeNameAge);
                    Int32 option = Convert.ToInt32(Console.ReadLine());
                    if (option == 1)
                    {
                        Console.WriteLine(Message.name);
                        var newName = Console.ReadLine();
                        getStudent.Name = newName;
                    }
                    else
                    if (option == 2)
                    {
                        Console.WriteLine(Message.age);
                        var newAge = Convert.ToInt32(Console.ReadLine());
                        getStudent.Age = Convert.ToInt32(newAge);
                    }
                    else
                    if (option == 3)
                    {
                        Console.WriteLine(Message.name);
                        string newName = Console.ReadLine();
                        Console.WriteLine(Message.age);
                        Int32 newAge = Convert.ToInt32(Console.ReadLine());
                        getStudent.Name = newName;
                        getStudent.Age  = newAge;
                    }
                    else
                    {
                        Console.WriteLine(Message.validNo);
                    }
                    _studentRepository.Update(getStudent);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            else
            if (dataValue == 2)
            {
                var StudentId = getStudent.Id;
                Console.WriteLine("Please choose a subject to change the mark");
                Console.WriteLine("English\nHindi\nMalayalam\n");
                string subName = Console.ReadLine();
                var    includeStudetSubject = _markRepository.IncludeStudentSubject(StudentId, subName);
                if (includeStudetSubject != null)
                {
                    Console.WriteLine("Please enter new score for {0}", subName);
                    includeStudetSubject.Score = Convert.ToInt16(Console.ReadLine());
                    _markRepository.Update(includeStudetSubject);
                }

                // _subjectRepository.Update(StudentId);
            }
            _studentRepository.SaveChanges();
        }