Exemple #1
0
 public ActionResult Edit(TeacherViewModel model)
 {
     try
     {
         if (string.IsNullOrEmpty(model.Name))
         {
             return(View());
         }
         // TODO: Add update logic here
         var result = TeacherService.Update(model);
         //var result = teacherlist.Where(e => e.Id == model.Id).FirstOrDefault();
         if (result == null)
         {
             return(RedirectToAction("Index", new { ErrorMsg = "用户不存在" }));
         }
         //var index = teacherlist.IndexOf(result);
         //result.Name = model.Name;
         //result.GradeId = model.GradeId;
         //result.Subject = model.Subject;
         //teacherlist[index] = result;
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Exemple #2
0
        public IHttpActionResult AddTeacher(TeacherModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var service = new TeacherService();

                int id = service.Add(BindingManager.ToTeacherEntity(model));
                if (id == 0)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResponseType.Error, Description = "Entity was not created."
                    }));
                }

                return(Ok(new ResponseModel()
                {
                    Result = ResponseType.Success
                }));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                return(InternalServerError(ex));
            }
        }
Exemple #3
0
        public ActionResult Edit(TeacherViewModel teacher)
        {
            string           username = Request.Cookies["UserSettings"].Values["UserName"];
            TeacherService   service  = new TeacherService();
            TeacherViewModel teacher2 = service.GetTeacherByTeacherName(username);

            if (teacher.UserName == "" | teacher.UserName == null)
            {
                teacher.UserName = teacher2.UserName;
            }
            if (teacher.FirstName == "" | teacher.FirstName == null)
            {
                teacher.FirstName = teacher2.FirstName;
            }
            if (teacher.LastName == "" | teacher.LastName == null)
            {
                teacher.LastName = teacher2.LastName;
            }
            if (teacher.Email == "" | teacher.Email == null)
            {
                teacher.Email = teacher2.Email;
            }
            if (teacher.PhoneNumber == "" | teacher.PhoneNumber == null)
            {
                teacher.PhoneNumber = teacher2.PhoneNumber;
            }
            if (teacher.HomeAddress == "" | teacher.HomeAddress == null)
            {
                teacher.HomeAddress = teacher2.HomeAddress;
            }
            teacher.TeacherID = teacher2.TeacherID;
            service.UpdateTeacher(teacher);
            return(RedirectToAction("MyProfile"));
        }
        public async Task CreateNew_InsertOneLecture_ReturnLectureId()
        {
            //Arrange

            var teacherService = new TeacherService(context, context);
            var teachers       = await teacherService.GetAll();

            var teacherId = teachers[teachers.Count - 1].Id;

            var subjectService = new SubjectService(context, context);
            var subjects       = await subjectService.GetAllSubjects();

            var subjectId = subjects[subjects.Count - 1].Id;

            LectureCreateModel model = new LectureCreateModel()
            {
                Name      = "Course .NET",
                Weekday   = "Wednesday",
                StartHour = 8,
                EndHour   = 10,
                HalfYear  = "A"
            };

            //Act
            var result = await lectureService.CreateNew(teacherId, subjectId, model);

            //Assert
            Assert.IsInstanceOfType(result, typeof(System.Guid));
        }
Exemple #5
0
        public void addTeacher()
        {
            try
            {
                Teacher Teacher = new Teacher();
                setValue(Teacher, context);

                HttpPostedFile hpf = context.Request.Files["headImgFile"];
                if (hpf != null)
                {
                    string serverPath = "/uploadFile/headImg/" + System.DateTime.Now.Ticks + "." + hpf.FileName.Split('.')[1];
                    string savePath   = context.Server.MapPath(serverPath); //路径,相对于服务器当前的路径
                    hpf.SaveAs(savePath);                                   //保存
                    Teacher.HeadImage = serverPath;
                }

                TeacherService s = new TeacherService();
                s.save(Teacher);

                context.Response.Write("1");
            }
            catch (Exception e)
            {
                context.Response.Write("0");
            }
        }
        public async Task UpdateLaboratory_GivenUpdatedLaboratory_ReturnLaboratoryId()
        {
            //Arrange
            var teacherService = new TeacherService(context, context);
            var teachers       = await teacherService.GetAll();

            var teacherId = teachers[teachers.Count - 1].Id;

            var laboratorysList = await laboratoryService.GetAll();

            var lastLaboratory = laboratorysList[laboratorysList.Count - 1];

            var updatedLaboratory = new LaboratoryCreateModel()
            {
                Name      = lastLaboratory.Name,
                Weekday   = "Friday",
                StartHour = 16,
                EndHour   = 18,
                Group     = lastLaboratory.Group
            };

            //Act
            var result = await laboratoryService.Update(teacherId, lastLaboratory.Id, updatedLaboratory);

            //Assert
            Assert.IsInstanceOfType(result, typeof(System.Guid));
        }
        public ActionResult GetAllTea()
        {
            Student              stu     = (Student)Session["student"];
            string               s       = "";
            TeacherService       teaser  = new TeacherService();
            ChoseThemeService    choser  = new ChoseThemeService();
            IQueryable <Teacher> tealist = teaser.GetAllTeaByDep((int)stu.Department.Dep_Id);
            List <Teacher>       tl      = tealist.ToList <Teacher>();

            for (int i = 0; i < tl.Count(); i++)
            {
                int status = 1;

                if (tl[i].Tea_ChoseCount >= tl[i].Tea_StuCount)
                {
                    status = 0;
                }
                s = s + tl[i].Tea_Name + "=" + status + "-";
            }
            //foreach (var item in tealist)
            //{
            //    int status=1;
            //    IQueryable<ChoseTheme> iq = choser.GetChosedThemeByTeacher((int)item.Tea_Id);
            //    if (iq.Count()>=item.Tea_StuCount)
            //    {
            //        status = 0;
            //    }
            //    s = s + item.Tea_Name + "=" + status+"-";
            //}
            Response.Write(s);
            Response.End();
            return(View());
        }
Exemple #8
0
        public ActionResult MySubjects(string email)
        {
            if (email == null)
            {
                return(RedirectToAction("Index"));
            }

            subjectService = new SubjectService();
            teacherService = new TeacherService();

            int teacherId = teacherService.GetTeacherIdFromEmail(email);

            Teacher teacher = teacherService.GetTeacherById(teacherId);

            IEnumerable <Subject> teacherSubjects = subjectService.getSubjectsByTeacherId(teacherId);

            if (teacher == null || teacherSubjects == null)
            {
                return(RedirectToAction("Index"));
            }

            List <TeacherSubjectNumberOfStudentsViewModel> viewModel = teacherService
                                                                       .CreateTeacherSubjectNumberOfStudentsViewModel(teacher, teacherSubjects);

            return(View(viewModel));
        }
Exemple #9
0
        public ActionResult ChangeTeacher(int?id)
        {
            if (id == null || !id.HasValue)
            {
                return(RedirectToAction("Index", "Home"));
            }

            teacherService = new TeacherService();
            subjectService = new SubjectService();

            // assign the value of teacher to be replaced to HireTeacherSingleton
            hireTeacherSingleton.TeacherToBeReplaced = teacherService.GetTeacherById((int)id);

            // assing the subject where teacher will be replaced
            hireTeacherSingleton.SubjectWhereTeacherWillBeReplaced = subjectService
                                                                     .getTeacherSubjectByTeacherId((int)id);

            // create view model for dropdown list choice between allocated and non-allocated teachers
            teacherService = new TeacherService();
            TeachersToReplaceViewModel teachers = null;

            List <Teacher> nonAllocatedTeachers = teacherService.GetNonAllocatedTeachers();

            teachers = new TeachersToReplaceViewModel()
            {
                Id       = 0,
                teachers = nonAllocatedTeachers
            };


            return(View("TypeOfReplacement", teachers));
        }
Exemple #10
0
        public void SearchTeacher()
        {
            //calling the clear component method to clear text from the latter
            clearComponents();

            String userInput = Microsoft.VisualBasic.Interaction.InputBox("Please enter Teacher ID Card", "Search Teacher Record");

            var teachers = TeacherService.Load(userInput);

            //Checking if user input matches a record in our teacher folder
            //and is not null.
            if (teachers != null)
            {
                this.txtName.Text      = teachers.Name;
                this.txtSurname.Text   = teachers.Surname;
                this.txtSubject.Text   = teachers.Subject;
                this.txtIDCard.Text    = teachers.IdCard;
                this.txtClass.Text     = teachers.ClassTeacher;
                this.txtAddress.Text   = teachers.Address;
                this.txtDOB.Text       = Convert.ToString(teachers.DateOfBirth);
                this.txtContactNo.Text = Convert.ToString(teachers.ContactNo);
                this.txtSalary.Text    = Convert.ToString(teachers.Salary);
                //the update button will be tured to enabled.
                this.btnUpdate.Enabled = true;
            }
            else
            {
                MessageBox.Show("No Records Found with given Teacher IDCard: " + userInput, "Search output");
                this.btnUpdate.Enabled = false;
            }
        }
Exemple #11
0
        public void UpdateTeacher()
        {
            Teacher myTeacher = new Teacher();

            myTeacher.Name         = this.txtName.Text;
            myTeacher.Surname      = this.txtSurname.Text;
            myTeacher.IdCard       = this.txtIDCard.Text;
            myTeacher.Subject      = this.txtSubject.Text;
            myTeacher.ClassTeacher = this.txtClass.Text;
            myTeacher.Address      = this.txtAddress.Text;
            myTeacher.DateOfBirth  = DateTime.Parse(this.txtDOB.Text.ToString());
            myTeacher.Salary       = float.Parse(this.txtSalary.Text);
            myTeacher.ContactNo    = Convert.ToInt32(this.txtContactNo.Text);

            //Updating the teacher record
            TeacherService.Save(myTeacher);

            //Showing a message to the user informing him that the update was successful
            MessageBox.Show("Teacher Record Updated Successfully", "Update Successfull", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //setting the button update to disabled
            this.btnUpdate.Enabled = false;

            //Calling the clear componet method to dispose from any text
            clearComponents();
        }
Exemple #12
0
        // GET: Subject/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null || !id.HasValue)
            {
                return(RedirectToAction("Index"));
            }

            subjectService        = new SubjectService();
            teacherService        = new TeacherService();
            studentSubjectService = new StudentSubjectService();

            Subject subject = subjectService.getSubjectById((int)id);

            Teacher teacher = teacherService.GetTeacherBySubjectId((int)id);

            IEnumerable <StudentSubject> studentSubjects =
                studentSubjectService.FindStudentSubjectsBySubject(subject);

            if (subject == null || teacher == null)
            {
                return(RedirectToAction("Index"));
            }

            List <TeacherStudentSubjectViewModel> viewModel = subjectService
                                                              .CreateTeacherStudentSubjectViewModel(subject, teacher, studentSubjects);

            return(View(viewModel));
        }
Exemple #13
0
        public void Create_TeacherWithData_NewTeacher()
        {
            var newTeacher = new DataPlus.Entities.Models.Teacher
            {
                Id             = Guid.NewGuid(),
                DocumentNumber = "5555555",
                FirstName      = "Jose",
                LastName       = "Santos",
                Email          = "*****@*****.**",
                Address        = "Street 5",
                City           = "City 2",
                DocumentType   = EDocumentType.CC,
                PhoneNumber    = "722222",
                Birth          = new DateTime(1965, 5, 5)
            };

            var repositoryWrapper = new Mock <IWrapperRepository>();

            repositoryWrapper.Setup(x => x.Teacher.GetAll()).Returns(_teacherList.AsQueryable);

            var teacherService   = new TeacherService(repositoryWrapper.Object, _logger);
            var numberOfTeachers = teacherService.GetAll().Count;

            teacherService.Create(newTeacher);
        }
Exemple #14
0
        public void GetById_SendAndIdToGetAnTeacher_TeacherFilteredById()
        {
            var repositoryWrapper = new Mock <IWrapperRepository>();
            var teacherId         = _teacherList.First().Id;

            repositoryWrapper.Setup(x => x.Teacher.GetById(teacherId)).Returns(new DataPlus.Entities.Models.Teacher
            {
                Id             = teacherId,
                DocumentNumber = "111111",
                FirstName      = "Pepe",
                LastName       = "Perez",
                Email          = "*****@*****.**",
                Address        = "Street 1",
                City           = "City 1",
                DocumentType   = EDocumentType.TI,
                PhoneNumber    = "7111111",
                Birth          = new DateTime(1980, 1, 1)
            });

            var teacherService = new TeacherService(repositoryWrapper.Object, _logger);
            var teacher        = teacherService.GetById(teacherId);

            Assert.True(teacher != null);
            Assert.True(teacher.FirstName == "Pepe");
            Assert.True(teacher.LastName == "Perez");
        }
Exemple #15
0
        public IHttpActionResult Post(Teacher teacher)
        {
            TeacherService service = new TeacherService();
            var            add     = service.Add(teacher);

            return(this.Ok(add));
        }
Exemple #16
0
        public ActionResult DeleteConfirmed(int?id)
        {
            if (id == 0 || !id.HasValue)
            {
                return(RedirectToAction("Index"));
            }

            teacherService = new TeacherService();
            subjectService = new SubjectService();
            staffService   = new StaffService();

            // pass subjects to singleton
            List <Subject> subjects = subjectService.getSubjectsByTeacherId((int)id);

            hireTeacherSingleton.Subjects = subjects;

            // remove teacher from staff
            staffService.DeleteTeacherFromStaffById((int)id);

            //delete the teacher
            teacherService.DeleteTeacherById((int)id);

            // if teacher had a subject allocated substitue him, if not don't
            if (subjects.Count == 0)
            {
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("HireNewTeacher"));
        }
        public async Task CreateNew_InsertOneLaboratory_ReturnLaboratoryId()
        {
            //Arrange

            var teacherService = new TeacherService(context, context);
            var teachers       = await teacherService.GetAll();

            var teacherId = teachers[teachers.Count - 1].Id;

            var subjectService = new SubjectService(context, context);
            var subjects       = await subjectService.GetAllSubjects();

            var subjectId = subjects[subjects.Count - 1].Id;

            LaboratoryCreateModel model = new LaboratoryCreateModel()
            {
                Name      = "Laboratory .NET",
                Weekday   = "Wednesday",
                StartHour = 10,
                EndHour   = 12,
                Group     = "A2"
            };

            //Act
            var result = await laboratoryService.CreateNew(teacherId, subjectId, model);

            //Assert
            Assert.IsInstanceOfType(result, typeof(System.Guid));
        }
Exemple #18
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ITeacherService, ITeacherRepository>();
            var model         = new ApiTeacherServerRequestModel();
            var validatorMock = new Mock <IApiTeacherServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new TeacherService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             validatorMock.Object,
                                             mock.DALMapperMockFactory.DALTeacherMapperMock,
                                             mock.DALMapperMockFactory.DALEventTeacherMapperMock,
                                             mock.DALMapperMockFactory.DALRateMapperMock,
                                             mock.DALMapperMockFactory.DALTeacherTeacherSkillMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <TeacherDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Exemple #19
0
        public void DeleteTeacherAndSubstituteHim(int id)
        {
            teacherService = new TeacherService();

            // also removes him from staff
            teacherService.DeleteTeacherAndSubstituteHim(id);
        }
Exemple #20
0
        private TeacherService CreateTeacherService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new TeacherService(userId);

            return(service);
        }
        public ActionResult StuXuanzeTheme()
        {
            Student           stu       = (Student)Session["student"];
            string            themename = Request["ketiming"];
            ThemeService      theser    = new ThemeService();
            ChoseThemeService choseser  = new ChoseThemeService();

            if (choseser.GetStuChoseTheme((int)stu.Stu_Id) != null)//没有选过就为true
            {
                Response.Write("不能选择过个课题");
                Response.End();
                return(View());
            }
            ;

            Theme      theme      = theser.GetThemeByThemeName(themename);
            ChoseTheme chosetheme = new ChoseTheme();

            chosetheme.Student = stu;
            chosetheme.Theme   = theme;
            chosetheme.Teacher = theme.Teacher;
            chosetheme.SubTime = DateTime.Now;
            if (choseser.AddChoseTheme(chosetheme))
            {
                TeacherService ter = new TeacherService();
                ter.UpdateTeaAddCount(theme.Teacher);
                Response.Write("选题成功");
                Response.End();
                return(View());
            }
            ;
            Response.Write("选题未成功");
            Response.End();
            return(View());
        }
Exemple #22
0
        static int UpdateScript2()
        {
            var teacher = TeacherService.Read(new Teacher()
            {
                Name = "Random Teacher", PassportData = 555190
            }, 1, 0).First();
            var speciality = SpecialityService.Read(new Speciality()
            {
                Name = "Random Speciality"
            }, 1, 0).First();

            // Предполагается, что действия до создания модели - это моделирование выбора пользователя

            var models = TimetableService.Read(new Timetable()
            {
                TeacherId = teacher.Id, SpecialityId = speciality.Id
            });

            DateTime startTime = DateTime.Now;

            foreach (var model in models)
            {
                model.ClassroomId = 1;
                TimetableService.Update(model);
            }
            DateTime finishTime = DateTime.Now;

            return((int)(finishTime - startTime).TotalMilliseconds);
        }
        public async Task UpdateLecture_GivenUpdatedLecture_ReturnLectureId()
        {
            //Arrange
            var teacherService = new TeacherService(context, context);
            var teachers       = await teacherService.GetAll();

            var teacherId = teachers[teachers.Count - 1].Id;

            var lecturesList = await lectureService.GetAll();

            var lastLecture = lecturesList[lecturesList.Count - 1];

            var updatedLecture = new LectureCreateModel()
            {
                Name      = lastLecture.Name,
                Weekday   = "Friday",
                StartHour = 14,
                EndHour   = 16,
                HalfYear  = lastLecture.HalfYear
            };

            //Act
            var result = await lectureService.Update(teacherId, lastLecture.Id, updatedLecture);

            //Assert
            Assert.IsInstanceOfType(result, typeof(System.Guid));
        }
Exemple #24
0
        static int SpecialScript0()
        {
            var teacher = TeacherService.Read(new Teacher()
            {
                Name = "Random Teacher", PassportData = 555190
            }, 1, 0).First();
            var speciality = SpecialityService.Read(new Speciality()
            {
                Name = "Random Speciality"
            }, 1, 0).First();
            DateTime  startTime = DateTime.Now;
            Timetable model     = new Timetable()
            {
                TeacherId = teacher.Id, SpecialityId = speciality.Id
            };

            var models = TimetableService.Read(model);

            foreach (var timetable in models)
            {
                Console.WriteLine("{0}: {1} {2} {3} {4}", timetable.Id, timetable.ExamDate.Value.ToString("dd.MM.yyyy"), timetable.Lesson, timetable.TeacherId, timetable.SpecialityId);
            }
            DateTime finishTime = DateTime.Now;

            return((int)(finishTime - startTime).TotalMilliseconds);
        }
Exemple #25
0
        public IHttpActionResult DeleteTeacher(int id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var service = new TeacherService();

                bool isSuccess = service.Delete(id);
                if (!isSuccess)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResponseType.Error, Description = "Entity was not deleted."
                    }));
                }

                return(Ok(new ResponseModel()
                {
                    Result = ResponseType.Success
                }));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                return(InternalServerError(ex));
            }
        }
Exemple #26
0
        static int AddScript2()
        {
            var teacher = TeacherService.Read(new Teacher()
            {
                Name = "Random Teacher", PassportData = 456278
            }, 1, 0).First();
            var speciality = SpecialityService.Read(new Speciality()
            {
                Name = "Random Speciality"
            }, 1, 0).First();

            Timetable[] models = new Timetable[30];
            for (int i = 0; i < models.Length; i++)
            {
                models[i] =
                    new Timetable()
                {
                    Lesson       = 5,
                    ExamDate     = DateTime.Now.AddDays(i),
                    TeacherId    = teacher.Id,
                    SpecialityId = speciality.Id,
                    ClassroomId  = 5,
                    DisciplineId = 5
                };
            }
            DateTime startTime = DateTime.Now;

            foreach (var model in models)
            {
                TimetableService.Create(model);
            }
            DateTime finishTime = DateTime.Now;

            return((int)(finishTime - startTime).TotalMilliseconds);
        }
Exemple #27
0
        private void TeachersList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            TeacherService teacherService  = new TeacherService();
            Teacher        selectedTeacher = TeachersList.SelectedItem as Teacher;

            StudentsList.DataContext = teacherService.GetStudentsByTeacherId(selectedTeacher.Id);
        }
 public ActionResult Register(StudentViewModel student)
 {
     if (student.Email.IsValidEmailAddress())
     {
         try
         {
             StudentService regViewModel = new StudentService();
             regViewModel.AddStudent(student);
         }
         catch (Exception ex)
         {
             ViewBag.Error = ex.Message;
             return(View("Register", student));
         }
         return(View("Register3", student));
     }
     else
     {
         TeacherService          ts          = new TeacherService();
         List <TeacherViewModel> listTeacher = new List <TeacherViewModel>();
         listTeacher      = ts.GetTeachers();
         ViewBag.Teachers = listTeacher;
         ModelState.AddModelError("", "");
         return(PartialView("_register"));
     }
 }
Exemple #29
0
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            TeacherService teacherService = new TeacherService();
            var            teacher        = await teacherService.GetTeacher(model.TeacherId);

            if (teacher == null)
            {
                return(BadRequest());
            }

            var user = new ApplicationUser()
            {
                UserName = model.Email, Email = model.Email, TeacherId = model.TeacherId
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            var resultAddRoles = await UserManager.AddToRolesAsync(user.Id, RolesEnum.Teacher);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            return(Ok());
        }
Exemple #30
0
        public void TestLoadTeacher_Succeeds()
        {
            Teacher teacher = TeacherService.Load("59780M");

            Assert.IsNotNull(teacher);
            Assert.AreEqual(teacher.IdCard, "59780M");
        }