public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            DataClassStudent.Student studentItem = null;

            if (_context.Students.Where(d => d.ClassRoomId == student.classRoomId && d.Id != student.id && d.StudentName.CompareTo(student.studentName) == 0).Count() > 0)
            {
                ModelState.AddModelError(string.Empty, "Your Student Name is duplicated ");
                return(Page());
            }



            studentItem = await _context.Students.Where(d => d.Id == student.id).FirstOrDefaultAsync();

            _mapper.Map(student, studentItem);


            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index", new { id = student.classRoomId }));
        }
Exemple #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            ClassRoom classRoom = null;

            if (room.id.HasValue == true)
            {
                classRoom = await _context.ClassRooms.Where(d => d.Id == room.id).FirstOrDefaultAsync();

                _mapper.Map(room, classRoom);

                //    classRoom=  _mapper.Map<ClassRoom>(room);
            }
            else
            {
                classRoom = _mapper.Map <ClassRoom>(room);
                _context.ClassRooms.Add(classRoom);
            }



            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Exemple #3
0
        public async Task <JsonResult> OnGetDeleteStudent(int id)
        {
            var stu = _context.Students.Where(d => d.Id == id).FirstOrDefault();

            if (stu == null)
            {
                return(new JsonResult("Student number is wrong"));
            }
            _context.Students.Remove(stu);
            await _context.SaveChangesAsync();


            return(new JsonResult("OK"));
        }
Exemple #4
0
        public async Task <JsonResult> OnGetDeleteClassRoom(int id)
        {
            try
            {
                var classRoom = _context.ClassRooms.Where(d => d.Id == id).FirstOrDefault();
                if (classRoom == null)
                {
                    return(new JsonResult("class number is wrong"));
                }
                _context.ClassRooms.Remove(classRoom);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                return(new JsonResult("you can't delete class there are some student in the class"));
            }

            return(new JsonResult("OK"));
        }