Exemplo n.º 1
0
        public IActionResult Remove(StudentDBModel student, int studentId)
        {
            var service  = HttpContext.RequestServices.GetService <StudentService>();
            var instance = ActivatorUtilities.CreateInstance <Remover>(HttpContext.RequestServices, service);

            instance._studentService.RemoveStudent(studentId);
            return(View("List", instance._studentService.GetStudentsList()));
        }
Exemplo n.º 2
0
 public void EditStudent(StudentDBModel student)
 {
     _context.Students.FirstOrDefault(x => x.Id.Equals(student.Id)).Name    = student.Name;
     _context.Students.FirstOrDefault(x => x.Id.Equals(student.Id)).Surname = student.Surname;
     _context.Students.FirstOrDefault(x => x.Id.Equals(student.Id)).Age     = student.Age;
     _context.Students.FirstOrDefault(x => x.Id.Equals(student.Id)).GroupId = student.GroupId;
     _context.Students.FirstOrDefault(x => x.Id.Equals(student.Id)).Status  = student.Status;
     _context.SaveChanges();
 }
Exemplo n.º 3
0
        public async Task <int> AddStudent(StudentDBModel student)
        {
            return(await Task.Run(() =>
            {
                _context.Students.Add(student);
                _context.SaveChanges();

                return student.Id;
            }));
        }
Exemplo n.º 4
0
        public IActionResult Edit(StudentDBModel student)
        {
            int num = student.Id;

            if (!ModelState.IsValid)
            {
                return(Edit(num));
            }
            var service = HttpContext.
                          RequestServices.
                          GetService <StudentService>();

            service.EditStudent(student);

            return(RedirectToAction("List", "Student", new { num = student.Id }));
        }
Exemplo n.º 5
0
        public static StudentVM ConvertStudentToVM(this StudentDBModel student)
        {
            if (student == null)
            {
                return(null);
            }

            return(new StudentVM
            {
                Id = student.Id,
                BirthDate = student.BirthDate,
                City = student.City,
                FirstName = student.FirstName,
                LastName = student.LastName,
                MiddleName = student.MiddleName,
                Gender = student.Gender,
                TabelNumber = student.TabelNumber
            });
        }
Exemplo n.º 6
0
 public StudentDBModel AddStudent(StudentDBModel student)
 {
     _context.Students.Add(new StudentDBModel
     {
         Id      = student.Id,
         Name    = student.Name,
         Surname = student.Surname,
         Age     = student.Age,
         GroupId = student.GroupId,
         Status  = student.Status
     });
     try
     {
         _context.SaveChanges();
     }
     catch (Exception e)
     {
     }
     return(student);
 }
Exemplo n.º 7
0
        public async Task <int> UpdateStudent(StudentDBModel newStudent)
        {
            return(await Task.Run(() =>
            {
                var oldStudent = _context.Students.FirstOrDefault(x => x.Id == newStudent.Id);
                if (oldStudent != null)
                {
                    oldStudent.FirstName = newStudent.FirstName;
                    oldStudent.LastName = newStudent.LastName;
                    oldStudent.MiddleName = newStudent.MiddleName;
                    oldStudent.BirthDate = newStudent.BirthDate;
                    oldStudent.City = newStudent.City;
                    oldStudent.Gender = newStudent.Gender;
                    oldStudent.TabelNumber = newStudent.TabelNumber;

                    _context.SaveChanges();
                }

                return newStudent.Id;
            }));
        }
Exemplo n.º 8
0
        public IActionResult Add(StudentDBModel student)
        {
            var newStudent = _studentService.AddStudent(student);

            return(View("List", _studentService.GetStudentsList()));
        }