Example #1
0
 public bool AddNewTeacher(Teacher newTeacher)
 {
     Teacher insertedTeacher = context.Teachers.Add(newTeacher);
     context.SaveChanges();
     if (insertedTeacher.Id > 0)
     {
         return true;
     }
     return false;
 }
 public EditTeacherViewModel(Teacher teacher)
 {
     _canExecute = true;
     _teacherId = teacher.Id;
     _teacherFirstname = teacher.Firstname;
     _teacherLastname = teacher.Lastname;
     _teacherMiddlename = teacher.Middlename;
     _teacherSpecialty = teacher.Specialty;
     _teacherDepartment = teacher.Parent;
     _teacherAvatar = teacher.RealAvatar;
 }
Example #3
0
        public void CreateTeacher_NotNull()
        {
            var teacher = new Models.Teacher()
            {
                Name = "TeacherTest",
            };
            var addedTeacher = _teacherRepository.GenericsDbContext.Add(teacher);

            _teacherRepository.GenericsDbContext.SaveChanges();
            Assert.NotNull(addedTeacher);
        }
 public async Task CreateNewTeacher(Teacher teacher)
 {
     await Task.Run(() =>
     {
         AppDelegate.Instance.dataController.CreateNewTeacher(() =>
         {
             AppDelegate.Instance.Context.ChangeLoaderVisible(false);
             AppDelegate.Instance.Alert.ShowAlert("Teacher successfully created! No errors reported.", true);
         },
         teacher);
     });
 }
Example #5
0
 public void AddNewTeacherToDb()
 {
     bool success = false;
     Teacher newTeacher = new Teacher()
     {
         FirstName = "Fornavn",
         LastName = "Efternavn",
         SocialSecurityNumber = 010170,
         Address = "Hallovej 123",
         ZipCode = 1234,
         City = "Randers ikke"
     };
     using (var tc = new TeacherContext())
     {
         success = tc.AddNewTeacher(newTeacher);
     }
     Assert.IsTrue(success);
 }
Example #6
0
        public static void Startup(TestContext testcontext)
        {
            Subject subject1 = new Subject() { Name = "Init subject" };
            Subject subject2 = new Subject() { Name = "Init subject2" };
            using (var sc = new SubjectContext())
            {
                sc.AddNewSubject(subject1);
                sc.AddNewSubject(subject2);
            }

            Class class1 = new Class() { Name = "Init class" };
            Class class2 = new Class() { Name = "Init class2" };
            using (var cc = new ClassContext())
            {
                cc.AddNewClass(class1);
                cc.AddNewClass(class2);
            }

            ICollection<Subject> subjects = new ObservableCollection<Subject>();
            ICollection<Class> classes = new ObservableCollection<Class>();

            subjects.Add(subject1);
            subjects.Add(subject2);

            classes.Add(class1);
            classes.Add(class2);

            Teacher newTeacher = new Teacher()
            {
                FirstName = "Ja",
                LastName = "Hallo",
                SocialSecurityNumber = 010203,
                Address = "Hallovej 123",
                ZipCode = 5678,
                City = "Viborg",
                Subjects = subjects,
                Classes = classes
            };
            using (var tc = new TeacherContext())
            {
                tc.AddNewTeacher(newTeacher);
            }
        }
        /// <summary>
        /// Edits an already created teacher based on the ID in the Teacher object provided.
        /// </summary>
        /// <param name="newTeacherData">Teacher object containing the new data.</param>
        /// <returns>True if success.</returns>
        public bool EditTeacher(Teacher newTeacherData)
        {
            Teacher oldTeacherData = Context.Teachers.Find(newTeacherData.Id);

            oldTeacherData.Subjects.Clear();
            foreach (Subject newSubject in newTeacherData.Subjects)
            {
                oldTeacherData.Subjects.Add(newSubject);
            }

            if (oldTeacherData != null)
            {
                Context.Entry(oldTeacherData).CurrentValues.SetValues(newTeacherData);
                if(Context.SaveChanges() > 0)
                {
                    return true;
                }
                return false;
            }
            return false;
        }
Example #8
0
        public async Task EditTeacher(Action action, Teacher teacher)
        {
            try
            {
                teacher.Avatar = SendImage(teacher.Avatar, teacher.Id, 1);
            }
            catch (Exception e)
            {

            }
            dataProvider.EditTeacher(teacher);
            action();
        }
Example #9
0
 public async Task CreateNewTeacher(Action action, Teacher teacher)
 {
     if (teacher.Avatar != "default")
     {
         teacher.Avatar = SendImage(teacher.Avatar, teacher.Id, 1);
     }
     try
     {
         dataProvider.CreateNewTeacher(teacher);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
     }
     action();
 }
Example #10
0
 public static string EditTeacherDataString(Teacher teacher)
 {
     return "queryName=Teacher&id=" + teacher.Id + "&Firstname=" + teacher.Firstname + "&Lastname=" + teacher.Lastname + "&Middlename=" + teacher.Middlename + "&Specialty=" + teacher.Specialty + "&Parent=" + teacher.Parent + "&Avatar=" + teacher.Avatar;
 }
Example #11
0
        public void AddNewTeacherClassesAndSubjectsToDb()
        {
            bool success = false;

            Subject subject1 = new Subject() { Name = "Test subject" };
            Subject subject2 = new Subject() { Name = "Test subject2" };
            using (var sc = new SubjectContext())
            {
                sc.AddNewSubject(subject1);
                sc.AddNewSubject(subject2);
            }

            Class class1 = new Class() { Name = "Test class" };
            Class class2 = new Class() { Name = "Test class2" };
            using (var cc = new ClassContext())
            {
                cc.AddNewClass(class1);
                cc.AddNewClass(class2);
            }

            ICollection<Subject> subjects = new ObservableCollection<Subject>();
            ICollection<Class> classes = new ObservableCollection<Class>();

            subjects.Add(subject1);
            subjects.Add(subject2);

            classes.Add(class1);
            classes.Add(class2);

            Teacher newTeacher = new Teacher()
            {
                FirstName = "Fornavn",
                LastName = "Efternavn",
                SocialSecurityNumber = 010170,
                Address = "Hallovej 123",
                ZipCode = 1234,
                City = "Randers ikke",
                Subjects = subjects,
                Classes = classes
            };
            using (var tc = new TeacherContext())
            {
                success = tc.AddNewTeacher(newTeacher);
            }
            Assert.IsTrue(success);
        }
 public CourseViewModel(DataContext context)
 {
     SelectedTeacher = new Teacher();
     this._context = context;
 }
Example #13
0
 public void CreateNewTeacher(Teacher teacher)
 {
     List<Teacher> teachers = GetAllTeachers();
     if (teacher.Id == -1) teacher.Id = AutoIncrementIndex(teachers);
     teachers.Add(teacher);
     TextWriter writer = new StreamWriter(fs_xml_file_Teachers);
     XmlSerializer serializer = new XmlSerializer(typeof(List<Teacher>));
     serializer.Serialize(writer, teachers);
     writer.Close();
 }
Example #14
0
 public void CreateNewTeacher(Teacher teacher)
 {
     if (teacher.Avatar == "default")
     {
         teacher.Avatar = CommonSettings.GetDefaultAvatar(0);
     }
     PostHandler(CommonSettings.CreateNewTeacherUrlString(), CommonSettings.CreateNewTeacherDataString(teacher));
 }
Example #15
0
 public void EditTeacher(Teacher teacher)
 {
     RemoveTeacher(teacher.Id);
     CreateNewTeacher(teacher);
 }
 public TeacherCRUDViewModel(DataContext context)
 {
     _context = context;
     SelectedTeacher = new Teacher();
 }
        public void DeleteTeacher()
        {
            //remove from db
            _context.Teachers.Remove(SelectedTeacher);
            _context.SaveChanges();

            //remove from ObservableCollection
            Teachers.Remove(SelectedTeacher);
            SelectedTeacher = new Teacher();
        }
 public void CreateTeacher()
 {
     SelectedTeacher = new Teacher();
 }
        /// <summary>
        /// The method the command use to save a Teacher
        /// </summary>
        /// <param name="sender">The EditTeacher window</param>
        private void SaveTeacher(EditTeacher sender)
        {
            TeacherListItemViewData teacherData = (TeacherListItemViewData)PersonData;
                            bool isSaved = false;
            EditTeacher et = sender;
            ICollection<Subject> teacherSubjects = new ObservableCollection<Subject>();

            Teacher teacherModel = new Teacher
            {
                Id = teacherData.Id,
                SocialSecurityNumber = teacherData.SocialSecurityNumber,
                FirstName = teacherData.FirstName,
                LastName = teacherData.LastName,
                Address = teacherData.Address,
                City = teacherData.City,
                ZipCode = teacherData.ZipCode
            };
            foreach (ComboboxItemViewModel item in subjectComboboxItem)
            {
                if (item.IsSelected)
                {
                    teacherModel.Subjects.Add(subjectList.Where(f => f.Id == item.Id).FirstOrDefault());
                }
            }
            foreach (ComboboxItemViewModel item in ClassComboboxItem)
            {
                if (item.IsSelected)
                {
                    teacherModel.Classes.Add(classList.Where(f => f.Id == item.Id).FirstOrDefault());
                }
            }

            using (TeacherContext tc = new TeacherContext())
            {

                if (isEdit)
                {
                    isSaved = tc.EditTeacher(teacherModel);
                }
                else
                {
                    isSaved = tc.AddNewTeacher(teacherModel);
                }
                if (isSaved)
                {
                    et.DialogResult = true;
                    et.Close();
                }
                ErrorMsg = "Teacher did not work";
            }
        }
Example #20
0
 public bool Validate(Teacher model)
 {
     if (StandartValidate(model.Firstname))
     {
         errMsg += "Invalid length of the field firstname! \n";
     }
     if (StandartValidate(model.Lastname))
     {
         errMsg += "Invalid length of the field lastname! \n";
     }
     if (StandartValidate(model.Middlename))
     {
         errMsg += "Invalid length of the field middlename! \n";
     }
     if (StandartValidate(model.Specialty))
     {
         errMsg += "Invalid length of the field specialty! \n";
     }
     if (model.Parent < -1 || model.Parent > maxSizeParentId)
     {
         errMsg += "Invalid length of the field parent! \n";
     }
     if (errMsg == null)
     {
         return true;
     }
     else
     {
         AppDelegate.Instance.Alert.ShowAlert(errMsg);
         return false;
     }
 }
Example #21
0
 public void EditTeacher(Teacher teacher)
 {
     PostHandler(CommonSettings.EditTeacherUrlString(), CommonSettings.EditTeacherDataString(teacher));
 }
Example #22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //需要登录才能看到
            AuthHelper.LoginCheck(Session, Request, Response, Server);
            AuthHelper.TeacherOnlyPage(Session, Request, Response, Server);

            var    teacher   = new Models.Teacher();
            string cidString = "";

            if (Session["user"] is Models.Teacher t)
            {
                teacher = t;
                //需要登录和cid(courseId)才能访问到的页面
                cidString = Request.QueryString["course"];
                if (string.IsNullOrEmpty(cidString))
                {
                    Response.Redirect("/Default.aspx");
                }
            }
            else
            {
                //登录的不是老师,转到登录界面
                Session.Remove("user");
                Response.Redirect("~/Login.aspx?pre=" + Server.UrlEncode(Request.Url.AbsoluteUri));
            }


            var courseAttachment = new CourseAttachmentServiceimpl();
            var teacherCourse    = new CourseServiceImpl();
            //获得当前老师教的课程
            var nowCourse     = new CourseServiceImpl().GetByCourseId(int.Parse(cidString));
            var nowAttachment = courseAttachment.Get(nowCourse);

            thisTeacherAttachment = nowAttachment;
            //var nowAttachment_id =((CourseAttachment)thisTeacherAttachment).AttachmentId;
            try
            {
                //通过js修改表单中提交的值,然后遍历正则找到 xxneededdeleted
                string pattern = @"\d{1,}neededdeleted";
                int    neededDeleteAttachmentId;
                for (int i = 0; i < Request.Form.Count; i++)
                {
                    if (Regex.IsMatch(Request.Form.Keys[i], pattern))
                    {
                        neededDeleteAttachmentId = int.Parse(Request.Form.Keys[i].ToString().Split('n')[0]);
                        var deletePath = new CourseAttachmentServiceimpl().GetByAttachmentId(neededDeleteAttachmentId);
                        if (new CourseAttachmentServiceimpl().DeleteByAttachemtId(neededDeleteAttachmentId))
                        {
                            //删除数据库成功
                            //删除当前目录下文件
                            var      temp = Server.MapPath("~" + deletePath.Path);
                            FileInfo file = new FileInfo(temp); //指定文件路径
                            try                                 //判断文件是否存在
                            {
                                //file.Attributes = FileAttributes.Normal;//将文件属性设置为普通,比方说只读文件设置为普通
                                file.Delete();//删除文件
                                Response.Write("<script language='javascript'>alert('删除成功!请按F5刷新');</script>");
                                //Response.Redirect(Request.Url.ToString());
                            }
                            catch (Exception ex)
                            { }
                            finally
                            {
                                Response.Redirect(Request.Url.ToString());
                            }
                            Response.Redirect(Request.Url.ToString());
                        }
                        else
                        {
                            //删除失败
                            Response.Write("<script language='javascript'>alert('删除失败!请重试');window.location.reload();</script>");
                        }
                    }
                }
            }
            catch (Exception)
            {
                //没有提交表单不做处理
                //Console.Write("...");
            }
        }