Esempio n. 1
0
        public HttpResponseMessage Add(HttpRequestMessage request, ClassroomViewModel classroom)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    Classroom newClassroom = new Classroom();
                    newClassroom.UpdateClassroom(classroom);
                    _classsRepository.Add(newClassroom);

                    _unitOfWork.Commit();

                    // Update view model
                    classroom = Mapper.Map <Classroom, ClassroomViewModel>(newClassroom);
                    response = request.CreateResponse(HttpStatusCode.Created, classroom);
                }

                return response;
            }));
        }
Esempio n. 2
0
        public async Task <IActionResult> PutClassroom(int id, ClassroomViewModel classroom)
        {
            if (classroom.Id != id)
            {
                throw new Exception(string.Format("Id và Id của lớp học không giống nhau!"));
            }

            try
            {
                await Task.Run(() =>
                {
                    classroom.DateModified = DateTime.Now;
                    _classroomService.Update(classroom);
                    _classroomService.SaveChanges();
                    return(Ok("Cập nhập thành công!"));
                });
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ClassroomExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        public HttpResponseMessage Update(HttpRequestMessage request, ClassroomViewModel classroom)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var classDb = _classsRepository.GetSingle(classroom.Id);
                    if (classDb == null)
                    {
                        response = request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid class.");
                    }
                    else
                    {
                        classDb.UpdateClassroom(classroom);
                        _classsRepository.Edit(classDb);

                        _unitOfWork.Commit();
                        response = request.CreateResponse(HttpStatusCode.OK, classroom);
                    }
                }

                return response;
            }));
        }
        public ActionResult Create(ClassroomViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var classroomRepository = new ClassroomRepository(_context);
                    classroomRepository.Create(viewModel.Name, viewModel.CourseIds);
                    _context.Save(_loggedUser);
                    TempData["MessageType"]  = "success";
                    TempData["MessageTitle"] = Resource.ClassroomManagementToastrTitle;
                    TempData["Message"]      = "Classroom added";
                    return(Redirect(TempData["BackURL"].ToString()));
                }
                catch (Exception ex)
                {
                    TempData["MessageType"]  = "error";
                    TempData["MessageTitle"] = Resource.ClassroomManagementToastrTitle;
                    TempData["Message"]      = ex.Message;
                }
            }

            var courseRepository = new CourseRepository(_context);

            ViewBag.Courses = new SelectList(CourseViewModel.FromEntityList(courseRepository.ListActiveCourses(), 0),
                                             "Id", "Name");
            return(View(viewModel));
        }
        // GET: Classroom
        public ActionResult IndexAdmin(string term, string searchFieldName, int page = 1)
        {
            var classroomRepository = new ClassroomRepository(_context);

            ViewBag.SearchFields = new SelectList(new[] { "Name", "Course" });
            return(View(ClassroomViewModel.FromEntityList(classroomRepository.Search(term, searchFieldName, page))));
        }
Esempio n. 6
0
 public static void UpdateClassroom(this Classroom classroom, ClassroomViewModel classroomVm)
 {
     classroom.Name         = classroomVm.Name;
     classroom.Totalstudent = classroomVm.Totalstudent;
     classroom.Descriptions = classroomVm.Descriptions;
     classroom.Active       = true;
     classroom.Delete       = false;
 }
Esempio n. 7
0
        /// <summary>
        /// 顯示所有教室資訊 照館別排列
        /// </summary>
        /// <returns></returns>
        public ActionResult Classroom()
        {
            try
            {
                //驗證授權:管理員
                var pass = roleAuth.AdminAuth();
                if (pass == true)
                {
                    ViewBag.UserName = roleAuth.UserName();
                    ViewBag.RoleName = "Admin";
                }
                else
                {
                    TempData["Msg"] = "無權限瀏覽該網頁,請登入會員瀏覽,謝謝!";
                    return(RedirectToAction("Login", "Home"));
                }

                StoreOperation     storeOperation     = new StoreOperation();
                ClassroomOperation classroomOperation = new ClassroomOperation();
                //取得所有館別ID
                var allStore = storeOperation.Get().Select(c => c.StoreNo);

                //取得所有教室
                var allClassroom = classroomOperation.Get();

                List <ClassroomViewModel> LstModel = new List <ClassroomViewModel>();

                //根據現有館別歸納出各場館下的教室
                foreach (var StoreNo in allStore)
                {
                    ClassroomViewModel model = new ClassroomViewModel();
                    model.ClassInfo = new List <Dictionary <string, string> >();

                    //取得同館別的教室
                    var LstClsRoom = allClassroom.Where(c => c.Store_No.Equals(StoreNo)).Select(c => c);

                    model.StoreNo   = StoreNo;
                    model.StoreName = storeOperation.GetName(StoreNo);
                    //取得同館別所有教室的Id及名稱
                    foreach (var item in LstClsRoom)
                    {
                        var DicClsInfo = new Dictionary <string, string>();
                        DicClsInfo.Add(item.ClassroomNo, item.Name);

                        model.ClassInfo.Add(DicClsInfo);
                    }

                    LstModel.Add(model);
                }

                return(View(LstModel));
            }
            catch (Exception ex)
            {
                TempData["Msg"] = ex.ToString();
                return(RedirectToAction("Logout", "Home"));
            }
        }
 public IActionResult Create(ClassroomViewModel model)
 {
     if (ModelState.IsValid)
     {
         ActionMessage response = classroomService.Create(model);
         return(RedirectToAction("ActionMessage", "Dashboard", response));
     }
     return(View(model));
 }
        public IActionResult Delete(int id)
        {
            ClassroomViewModel viewModel = this.classroomsServices.Classroom <ClassroomViewModel>(id);

            if (!this.ModelState.IsValid)
            {
                return(this.NotFound());
            }

            return(this.View(viewModel));
        }
        // GET: Classrooms/Create
        public IActionResult Create()
        {
            var model = new ClassroomViewModel()
            {
                Subjects   = _context.Subjects.ToList(),
                Teachers   = _context.Teachers.ToList(),
                Institutes = _context.Institutes.Include(c => c.UniversityProvider).ToList()
            };

            return(View(model));
        }
 public bool Update(ClassroomViewModel classroomVm)
 {
     try
     {
         var classRoom = Mapper.Map <ClassroomViewModel, Classroom>(classroomVm);
         _classRoomRepository.Update(classRoom);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 12
0
        public IActionResult CreateClassroom(ClassroomViewModel viewModel)
        {
            string id            = viewModel.ClassroomId;
            string classroomName = viewModel.ClassroomName;
            string creatorName   = viewModel.CreatorName;


            _classroomService.AddClassroom(id, classroomName, creatorName);

            ViewBag.message = "The classroom has been created successfully!";

            return(View(viewModel));
        }
Esempio n. 13
0
        public IActionResult ShowClassroom(string id)
        {
            var classroom = _classroomService.GetClassroomByClassroomId(id);

            ClassroomViewModel viewModel = new ClassroomViewModel
            {
                ClassroomId   = classroom.ClassroomId,
                ClassroomName = classroom.Name,
                CreatorName   = classroom.CreatorName,
                Messages      = _messageService.GetMessagesInClassroom(id),
            };

            return(View(viewModel));
        }
Esempio n. 14
0
        public HttpResponseMessage Get(HttpRequestMessage request, Guid id)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                var classroom = _classsRepository.GetSingle(id);

                ClassroomViewModel classVM = Mapper.Map <Classroom, ClassroomViewModel>(classroom);

                response = request.CreateResponse(HttpStatusCode.OK, classVM);

                return response;
            }));
        }
Esempio n. 15
0
        public IActionResult JoinClassroom(HomeViewModel model)
        {
            string userId    = GetUserId();
            var    classroom = _classroomRepository.GetClassroomByAccessCode(model.ClassroomAccessCode);

            if (classroom == null)
            {
                model.ErrorMessage = "There is no active classroom with the given access code. Please try again.";
                return(View("Index", model));
            }

            ClassroomViewModel viewModel = SetupViewModel(userId, classroom);

            return(View("Classroom", viewModel));
        }
        public ActionResult Edit(Guid id)
        {
            var classroomRepository = new ClassroomRepository(_context);

            var classroom = classroomRepository.GetById(id);

            var courses = ReorderCourses(classroom);

            ViewBag.Courses = new SelectList(CourseViewModel.FromEntityList(courses, 0), "Id", "Name");

            var userRepository = new UserRepository(_context);

            ViewBag.Students = new SelectList(userRepository.ListActiveStudents(), "id", "Name");

            return(View(ClassroomViewModel.FromEntity(classroom)));
        }
        public ActionResult ManageClassRoom(ClassroomViewModel classRoomViewModel)
        {
            GetUIDropdownLists();
            var classRoomModel = (Classroom)Mapper.Map(classRoomViewModel, typeof(ClassroomViewModel), typeof(Classroom));

            if (classRoomViewModel.Select != null)
            {
                if (classRoomViewModel.ClassroomId < 1 || classRoomViewModel.CalendarBookingId < 1)
                {
                    ModelState.AddModelError("ClassroomId", "ClassroomId and CalendarId are required");
                }
                if (ModelState.IsValid)
                {
                    var calendar  = _repositoryServices.GetTeacherCalendarByBookingId(classRoomViewModel.CalendarBookingId);
                    var classroom = _repositoryServices.GetClassroomById(classRoomViewModel.ClassroomId);
                    classRoomViewModel = (ClassroomViewModel)Mapper.Map(classroom, typeof(Classroom), typeof(ClassroomViewModel));
                    classRoomViewModel.CalendarBookingId = (int)calendar.CalendarBookingId;
                    classRoomViewModel.SubjectId         = calendar.SubjectId;
                    ModelState.Clear();
                }
                return(View("ManageClassRoom", classRoomViewModel));
            }

            if (ModelState.IsValid)
            {
                if (classRoomViewModel.Delete != null)
                {
                    var classroom = _repositoryServices.GetClassroomById(classRoomViewModel.ClassroomId);
                    _repositoryServices.DeleteClassroom(classroom);
                    return(View("SuccessfullCreation"));
                }
                else
                {
                    var calendar = _repositoryServices.GetTeacherCalendarByBookingId(classRoomViewModel.CalendarBookingId);
                    _repositoryServices.ManageClassRoom(classRoomModel);
                    calendar.SubjectId = classRoomModel.SubjectId;
                    calendar.ClassId   = (int)classRoomModel.ClassroomId;
                    _repositoryServices.SaveOrUpdateCalendar(calendar);
                    return(View("SuccessfullCreation"));
                }
            }
            return(View("ManageClassRoom", classRoomViewModel));
        }
        public ActionMessage Create(ClassroomViewModel model)
        {
            var response    = new ActionMessage();
            var dbClassroom = classroomRepository.GetByRoomNo(model.RoomNumber);

            if (dbClassroom == null)
            {
                var newClassroom = new Classroom()
                {
                    RoomNumber = model.RoomNumber,
                    Capacity   = model.Capacity
                };
                response.Message = "Classroom has been successfully created!";
                classroomRepository.Add(newClassroom);
            }
            else
            {
                response.Error = "Create failed. Room number already exists!";
            }
            return(response);
        }
        public async Task <ActionResult> Edit(Guid id, ClassroomViewModel viewModel)
        {
            var classroomRepository = new ClassroomRepository(_context);
            var classroom           = classroomRepository.GetById(id);

            if (ModelState.IsValid)
            {
                try
                {
                    await classroomRepository.UpdateAsync(new SmtpSender(),
                                                          classroom,
                                                          viewModel.Name,
                                                          viewModel.Active,
                                                          viewModel.CourseIds,
                                                          viewModel.StudentIds,
                                                          _loggedUser);

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

            var courses = ReorderCourses(classroom);

            ViewBag.Courses = new SelectList(CourseViewModel.FromEntityList(courses, 0), "Id", "Name");

            var userRepository = new UserRepository(_context);

            ViewBag.Students = new SelectList(userRepository.ListActiveStudents(), "id", "Name");

            return(View(viewModel));
        }
Esempio n. 20
0
        public ActionMessage Create(int classroomId, string subjectTitle, DateTime examStart, DateTime examEnd, string userId)
        {
            ActionMessage      response = new ActionMessage();
            ClassroomViewModel model    = classroomService.GetById(classroomId);

            if (model.Exams.Count > 0)
            {
                bool isValid = model.Exams.Where(x => examStart > x.ExamEnd || examEnd < x.ExamDate).Any();
                if (!isValid)
                {
                    response.Error = "This time is already scheduled. Please check the classroom details";
                    return(response);
                }
            }

            if (examStart <= DateTime.Now.AddDays(14))
            {
                response.Error = "Invalid date! Exam must be scheduled 14 days in advance";
            }
            else if (examStart > examEnd)
            {
                response.Error = "Invalid date! Your end time is before your start time !!!";
            }
            else
            {
                Exam exam = new Exam()
                {
                    ClassroomId = classroomId,
                    SubjectId   = subjectService.GetByTitle(subjectTitle).Id,
                    ExamDate    = examStart,
                    ExamEnd     = examEnd,
                    CreatedBy   = userId,
                };

                examRepositoty.Add(exam);
                response.Message = "Exam successfully created";
            }

            return(response);
        }
Esempio n. 21
0
        public async Task <ActionResult <ClassroomViewModel> > PostClassroom(ClassroomViewModel classroom)
        {
            if (classroom != null)
            {
                try
                {
                    await Task.Run(() =>
                    {
                        classroom.DateCreated = DateTime.Now;
                        _classroomService.Add(classroom);
                        _classroomService.SaveChanges();
                        return(Ok("Thêm phòng học thành công!"));
                    });
                }
                catch
                {
                    throw new Exception(string.Format("Lỗi khi thêm dữ liệu"));
                }
            }

            return(CreatedAtAction("GetReceiptType", new { id = classroom.Id }, classroom));
        }
        public async Task SaveClassroomAsync(ClassroomViewModel viewModel)
        {
            await Task.CompletedTask;
            var classroomRepository = _unitOfWork.Repository <Classroom>();

            if (viewModel.IsNew)
            {
                var model = new Classroom
                {
                    ClassroomName = viewModel.ClassroomName,
                    ObjectState   = ObjectState.Added
                };
                classroomRepository.SaveAllChanges(model);
            }
            else
            {
                var model = classroomRepository.Single(x => x.Id == viewModel.Id);

                model.ClassroomName = viewModel.ClassroomName;
                model.ObjectState   = ObjectState.Modified;

                classroomRepository.SaveAllChanges(model);
            }
        }
        public async Task <IActionResult> Create(ClassroomViewModel model)
        {
            var classroom = new Classroom()
            {
                Code              = model.Code,
                ClassLocation     = model.ClassLocation,
                ClassSubject      = _context.Subjects.Find(model.ClassSubjectId),
                ClassTeacher      = _context.Teachers.Find(model.ClassTeacherId),
                InstituteProvider = _context.Institutes.Find(model.InstituteProviderId),
                IsActive          = model.IsActive,
                IsOfficial        = model.IsOfficial,
                ClassDays         = new List <ClassDay>()
            };

            if (ModelState.IsValid)
            {
                _context.Add(classroom);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
Esempio n. 24
0
        public IActionResult RegisterTeacher(mo.UserModel us)
        {
            us.RoleId = 1;

            var classroom = new Classroom()
            {
                Name = us.Name
            };

            if (ClassroomViewModel.SetClassroom(classroom))
            {
                classroom = ClassroomViewModel.GetClassroomByName(classroom.Name);

                var user = new User()
                {
                    Username    = us.Username,
                    RoleId      = us.RoleId,
                    Quizzes     = us.Quizzes,
                    Password    = us.Password,
                    ClassroomId = classroom.ClassroomId
                };

                if (UserViewModel.SetUser(user))
                {
                    //HttpContext.Session.SetString("Username", us.Username);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(RedirectToAction("Register", "Home"));
                }
            }

            return(RedirectToAction("Register", "Home"));
        }
        public async Task <IActionResult> SaveTeacher([FromBody] ClassroomViewModel viewModel)
        {
            await _classroomApi.SaveClassroomAsync(viewModel);

            return(CreateSuccessWebResult(viewModel.IsNew ? "Classroom Record Created." : "Classroom Record Updated."));
        }
Esempio n. 26
0
 public IActionResult CreateClassroom(ClassroomViewModel model)
 {
     classroomServices.AddClassrom(userManager.GetUserId(User), model.Name, model.ClassCode);
     return(RedirectToAction("Index", "Home"));
 }
        public ActionResult Search(string term, string searchFieldName, int page = 1)
        {
            var classroomRepository = new ClassroomRepository(_context);

            return(Json(ClassroomViewModel.FromEntityList(classroomRepository.Search(term, searchFieldName, page))));
        }
        public IActionResult Details(int id)
        {
            ClassroomViewModel viewModel = this.classroomsServices.Classroom <ClassroomViewModel>(id);

            return(this.View(viewModel));
        }
Esempio n. 29
0
 public IActionResult Index(ClassroomViewModel viewModel)
 {
     return(View("Classroom", viewModel));
 }
Esempio n. 30
0
 public IActionResult CreateQuestion(ClassroomViewModel model)
 {
     return(View("Classroom", _classroomService.CreateQuestion(model.AccessCode, model.Question, GetUserId())));
 }