Beispiel #1
0
        /// <summary>
        /// Convert ClassRoomViewModel to ClassRoom
        /// </summary>
        /// <param name="classRoomViewModel"></param>
        /// <returns>ClassRoom</returns>
        public static ClassRoom MapToClassRoom(this ClassRoomViewModel classRoomViewModel)
        {
            List <Student> students  = new List <Student>();
            var            classRoom = new ClassRoom();

            if (classRoomViewModel == null)
            {
                return(classRoom);
            }
            if (classRoom.ListStudents.Count > 0)
            {
                foreach (StudentViewModel sMV in classRoomViewModel.ListStudents)
                {
                    Student s = new Student();
                    s = MapToStudent(sMV);
                    students.Add(s);
                }
            }
            classRoom = new ClassRoom()
            {
                Id           = classRoomViewModel.Id,
                Number       = classRoomViewModel.Number,
                Name         = classRoomViewModel.Name,
                ListStudents = students
            };
            return(classRoom);
        }
        public ActionResult Create()
        {
            List <SelectListItem> types = new List <SelectListItem>();

            types.Add(new SelectListItem()
            {
                Text  = "Teorinė",
                Value = "Teorinė"
            });
            types.Add(new SelectListItem()
            {
                Text  = "Praktinė",
                Value = "Praktinė"
            });
            types.Add(new SelectListItem()
            {
                Text     = "-",
                Value    = "",
                Selected = true
            });

            ClassRoomViewModel model = new ClassRoomViewModel()
            {
                TypesList = types
            };

            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> PutClassRoom([FromRoute] int id, [FromBody] ClassRoomViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var classRoom = new ClassRoom
            {
                Id       = id,
                Name     = model.Name,
                Building = _context.Buildings.Where(b => b.Id == model.BuildingId).First()
            };

            _context.Entry(classRoom).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClassRoomExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #4
0
        /// <summary>
        /// Convert Student to StudentViewModel
        /// </summary>
        /// <param name="student"></param>
        /// <returns>StudentViewModel</returns>
        public static StudentViewModel MapToStudentViewModel(this Student student)
        {
            List <ClassRoomViewModel> ListClassRoomViewModels = new List <ClassRoomViewModel>();
            var studentViewModel = new StudentViewModel();

            if (student == null)
            {
                return(studentViewModel);
            }
            if (student.ListClassRooms.Count > 0)
            {
                foreach (ClassRoom classRoom in student.ListClassRooms)
                {
                    ClassRoomViewModel classRoomVM = new ClassRoomViewModel();
                    classRoomVM = MapToClassRoomViewModel(classRoom);
                    ListClassRoomViewModels.Add(classRoomVM);
                }
            }
            studentViewModel = new StudentViewModel()
            {
                Id             = student.Id,
                Name           = student.Name,
                ListClassRooms = ListClassRoomViewModels
            };
            return(studentViewModel);
        }
Beispiel #5
0
        public ActionResult Create()
        {
            List <StudentViewModel> students = new List <StudentViewModel>();

            for (int i = 1; i <= 10; i++)
            {
                StudentViewModel student = new StudentViewModel()
                {
                    Id   = i,
                    Name = "Nom" + i.ToString()
                };
                students.Add(student);
            }

            List <ClassRoomViewModel> classRooms = new List <ClassRoomViewModel>();
            ClassRoomViewModel        classRoom  = new ClassRoomViewModel()
            {
                Id           = 1,
                Name         = "Salle101",
                Number       = 101,
                ListStudents = students
            };

            classRooms.Add(classRoom);
            ViewBag.StudentList = students.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Id.ToString()
            }).AsEnumerable();
            ViewBag.ClassRoomList = classRooms.Select(x => new SelectListItem()
            {
                Text = x.Name, Value = x.Id.ToString()
            }).AsEnumerable();
            return(View("AddStudentAttendance"));
        }
Beispiel #6
0
        public void Save(ClassRoomViewModel vm)
        {
            var entity = new ClassRoomEntity(0);

            vm.Bind(entity);
            ClassService.Save(entity);
        }
Beispiel #7
0
        /// <summary>
        /// Convert ClassRoom to ClassRoomViewModel
        /// </summary>
        /// <param name="classRoom"></param>
        /// <returns>ClassRoomViewModel</returns>
        public static ClassRoomViewModel MapToClassRoomViewModel(this ClassRoom classRoom)
        {
            List <StudentViewModel> studentVMs = new List <StudentViewModel>();
            var classRoomViewModel             = new ClassRoomViewModel();

            if (classRoom == null)
            {
                return(classRoomViewModel);
            }
            if (classRoom.ListStudents.Count > 0)
            {
                foreach (Student s in classRoom.ListStudents)
                {
                    StudentViewModel sMV = new StudentViewModel();
                    sMV = MapToStudentViewModel(s);
                    studentVMs.Add(sMV);
                }
            }
            classRoomViewModel = new ClassRoomViewModel()
            {
                Id           = classRoom.Id,
                Number       = classRoom.Number,
                Name         = classRoom.Name,
                ListStudents = studentVMs
            };
            return(classRoomViewModel);
        }
Beispiel #8
0
 public static Classroom ToDomain(this ClassRoomViewModel model)
 {
     return(new Classroom
     {
         Id = model.Id,
         Name = model.Name,
         Location = model.Location
     });
 }
        public ActionResult Details(int id)
        {
            if (Session["log"] == null)
            {
                return(RedirectToAction("Login", "Home", null));
            }
            ClassRoomViewModel ClassRoom = ClassRoomService.GetByID(id);

            return(View(ClassRoom));
        }
Beispiel #10
0
 public static void PutOne(ClassRoomViewModel classRoomModel)
 {
     using (var context = new FinalSchool())
     {
         var classRoom = context.ClassRooms.Find(classRoomModel.ClassId);
         classRoom.Name = classRoomModel.Name;
         // classRoom.LevelId = classRoomModel.LevelId;
         classRoom.ClassRoomId = classRoomModel.ClassId;
         classRoom.Level.Name  = classRoomModel.LevelName;
         context.SaveChanges();
     }
 }
        public void Update(ClassRoomViewModel model)
        {
            var classroom = _classroomRepository.FindById(model.Id);

            if (classroom == null)
            {
                throw new Exception();
            }

            classroom.Name     = model.Name;
            classroom.Location = model.Location;

            _classroomRepository.Update(classroom);
        }
Beispiel #12
0
 public static ClassRoomViewModel GetOne(int id)
 {
     using (var context = new FinalSchool())
     {
         var classRoom      = context.ClassRooms.Find(id);
         var classRoomModel = new ClassRoomViewModel()
         {
             Name = classRoom.Name,
             //  LevelId = classRoom.LevelId,
             ClassId   = classRoom.ClassRoomId,
             LevelName = classRoom.Level.Name,
         };
         return(classRoomModel);
     }
 }
Beispiel #13
0
 public IActionResult UpdateClassRoom(ClassRoomViewModel classRoom)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             throw new Exception(ModelState.ToString());
         }
         _classRoomService.Update(classRoom);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Beispiel #14
0
 public static int PostOne(ClassRoomViewModel classRoomModel)
 {
     using (var context = new FinalSchool())
     {
         var levelId   = context.Levels.FirstOrDefault(x => x.Name == classRoomModel.LevelName).LevelId;
         var classRoom = new ClassRoom()
         {
             Name        = classRoomModel.Name,
             LevelId     = levelId,
             ClassRoomId = classRoomModel.ClassId,
         };
         context.ClassRooms.Add(classRoom);
         context.SaveChanges();
         return(classRoom.ClassRoomId);
     }
 }
Beispiel #15
0
        public ActionResult Index(int id, int loadParameters)
        {
            var classRoomViewModel = new ClassRoomViewModel();

            try
            {
                classRoomViewModel.ClassRooms        = _classRoomService.Get();
                classRoomViewModel.LoadParameters    = (PlanSectionLoadParameters)loadParameters;
                classRoomViewModel.SelectedClassRoom = id;

                return(PartialView(classRoomViewModel));
            }
            catch (Exception)
            {
                return(Json(new { message = Localization.Localization.ErrorGeneralException, success = false }));
            }
        }
        public ActionResult Create(ClassRoomViewModel model)
        {
            if (ModelState.IsValid)
            {
                ClassRoom classRoom = new ClassRoom()
                {
                    Name           = model.Name,
                    NumberOfPlaces = model.NumberOfPlaces,
                    IsPCavailable  = model.IsPCAvailable,
                    Type           = model.Type
                };
                db.ClassRooms.Add(classRoom);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Beispiel #17
0
        public async Task <IActionResult> PostClassRoom([FromBody] ClassRoomViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var classRoom = new ClassRoom
            {
                Name     = model.Name,
                Building = _context.Buildings.Where(b => b.Id == model.BuildingId).First()
            };

            _context.ClassRooms.Add(classRoom);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetClassRoom", new { id = classRoom.Id }, classRoom));
        }
Beispiel #18
0
 public static IEnumerable <ClassRoomViewModel> GetClassesToLevel(string levelName)
 {
     using (var context = new FinalSchool())
     {
         var levelId         = context.Levels.FirstOrDefault(x => x.Name == levelName).LevelId;
         var classrooms      = context.ClassRooms.Where(x => x.LevelId == levelId).ToList();
         var coursesViewList = new List <ClassRoomViewModel>();
         foreach (var klass in classrooms)
         {
             var coureView = new ClassRoomViewModel()
             {
                 ClassId   = klass.ClassRoomId,
                 Name      = klass.Name,
                 LevelName = klass.Level.Name
             };
             coursesViewList.Add(coureView);
         }
         return(coursesViewList);
     }
 }
 public void Put(ClassRoomViewModel classRoomViewModel)
 {
     ClassRoomService.PutOne(classRoomViewModel);
 }
Beispiel #20
0
 public ActionResult Post([FromBody] ClassRoomViewModel vm)
 {
     ViewModelService.Save(vm);
     return(Ok());
 }
 public void Create(ClassRoomViewModel model)
 {
     _classroomRepository.Create(model.ToDomain());
 }
 public int Post(ClassRoomViewModel classRoomViewModel)
 {
     return(ClassRoomService.PostOne(classRoomViewModel));
 }