protected void btnUpdate_Click(object sender, EventArgs e)
        {
            int teacherID = Convert.ToInt32(lblTID.Text);

            ctx = new TeacherInformationDataContext();

            TeacherInformation teacher = new TeacherInformation();

            teacher = ctx.TeacherInformations.Single(x => x.TeacherID == teacherID);

            teacher.TeacherName = txtName.Text;
            teacher.Email       = txtEmail.Text;
            teacher.Phone       = txtMobile.Text;
            teacher.DOB         = Convert.ToDateTime(txtDOB.Text);
            teacher.Course      = ddlCourse.SelectedValue;
            teacher.Address     = txtAddress.Text;


            ctx.SubmitChanges();

            ShowAlert("Data Updated Successfully!!");
            this.DataLoad();
            ClearData();


            //=============
        }
        public async Task <IActionResult> Edit(int id, [Bind("TeacherID,TeacherName,DOB,TeachersCellPhone,Religion,TeacherAddress,ImagePath,ClassID")] TeacherInformation teacherInformation)
        {
            if (id != teacherInformation.TeacherID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(teacherInformation);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TeacherInformationExists(teacherInformation.TeacherID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClassID"] = new SelectList(_context.ClassInformation, "ClassID", "ClassName", teacherInformation.ClassID);
            return(View(teacherInformation));
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int teacerId = Convert.ToInt32(lblTID.Text);

            using (ctx = new TeacherInformationDataContext())
            {
                TeacherInformation teacher = (from c in ctx.TeacherInformations
                                              where c.TeacherID == teacerId
                                              select c).FirstOrDefault();
                ctx.TeacherInformations.DeleteOnSubmit(teacher);
                ctx.SubmitChanges();
            }
            ShowAlert("Data Deleted Successfully!!");
            this.DataLoad();
            ClearData();
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            using (ctx = new TeacherInformationDataContext())
            {
                TeacherInformation teacher = new TeacherInformation
                {
                    TeacherName = txtName.Text,
                    Email       = txtEmail.Text,
                    Phone       = txtMobile.Text,
                    DOB         = Convert.ToDateTime(txtDOB.Text),
                    Course      = ddlCourse.SelectedValue,
                    Address     = txtAddress.Text
                };
                ctx.TeacherInformations.InsertOnSubmit(teacher);
                ctx.SubmitChanges();
            }

            ShowAlert("Data Inserted Successfully!!");
            this.DataLoad();

            ClearData();
        }
        public async Task <IActionResult> Create([Bind("TeacherID,TeacherName,DOB,TeachersCellPhone,Religion,TeacherAddress,ImagePath,ClassID")] TeacherInformation teacherInformation, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teacherInformation);
                await _context.SaveChangesAsync();

                // Code to upload image if not null
                if (file != null || file.Length != 0)
                {
                    // Create a File Info
                    FileInfo fi = new FileInfo(file.FileName);

                    // This code creates a unique file name to prevent duplications
                    // stored at the file location
                    var newFilename = teacherInformation.TeacherID + "_" + String.Format("{0:d}",
                                                                                         (DateTime.Now.Ticks / 10) % 100000000) + fi.Extension;
                    var webPath = hostingEnvironment.WebRootPath;
                    var path    = Path.Combine("", webPath + @"\ImageFiles\" + newFilename);

                    // IMPORTANT: The pathToSave variable will be save on the column in the database
                    var pathToSave = @"/ImageFiles/" + newFilename;

                    // This stream the physical file to the allocate wwwroot/ImageFiles folder
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }

                    // This save the path to the record
                    teacherInformation.ImagePath = pathToSave;
                    _context.Update(teacherInformation);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClassID"] = new SelectList(_context.ClassInformation, "ClassID", "ClassName", teacherInformation.ClassID);
            return(View(teacherInformation));
        }
Beispiel #6
0
        public TeacherInformation GetTeacherInformation(Teacher teacher)
        {
            if (teacher == null)
            {
                throw new ArgumentNullException(nameof(teacher));
            }

            TeacherInformation teacherInformation = new TeacherInformation();

            teacherInformation.FullName = teacher.FullName;
            List <Course>   courses           = _courseRepository.GetAll();
            List <Didactic> didactics         = _didacticRepository.GetAll();
            List <Course>   filteredCourses   = new List <Course>();
            List <Didactic> filteredDidactics = new List <Didactic>();

            foreach (var didactic in didactics)
            {
                if (didactic.TeacherId == teacher.Id)
                {
                    filteredDidactics.Add(didactic);
                }
            }
            foreach (var course in courses)
            {
                foreach (var didactic in filteredDidactics)
                {
                    if (course.Id == didactic.CourseId)
                    {
                        filteredCourses.Add(course);
                    }
                }
            }
            teacherInformation.Courses = filteredCourses;

            return(teacherInformation);
        }