public async Task <ApiResult <TeacherVm> > GetTeacherById(Guid id) { var user = await _userManager.FindByIdAsync(id.ToString()); if (user == null) { return(new ApiErrorResult <TeacherVm>("Tài khoản không tồn tại")); } var newStudent = await _context.Students.FindAsync(user.Id); var queryCourse = from c in _context.Courses where c.Id_Teacher == id select new { c }; var dataCourse = await queryCourse.Select(x => new TeacherCourse() { Id_Course = x.c.Id_Course, NameCourse = x.c.Name, DateBegin = x.c.DateBegin, DateEnd = x.c.DateEnd }).ToListAsync(); var userVm = new TeacherVm() { Id = user.Id, FullName = user.FullName, Email = user.Email, UserName = user.UserName, //UrlImg=user.UrlImg, TeacherCourses = dataCourse, }; return(new ApiSuccessResult <TeacherVm>(userVm)); }
public ActionResult AddTeacher() { var Data = absd.Genders.ToList(); var TachVm = new TeacherVm() { Genders = Data }; return(View(TachVm)); }
public Task UpdateTeacher([FromBody] TeacherVm teacherVm) { Teacher teacher = new Teacher { Id = teacherVm.Id, Surname = teacherVm.Surname, Name = teacherVm.Name, Patronymic = teacherVm.Patronymic, Degree = teacherVm.Degree, AdditionalInfo = teacherVm.AdditionalInfo, PictureId = teacherVm.PictureId, }; return(_teacherRepository.UpdateTeacher(teacher)); }
public Task UpdateTeacher([FromBody] TeacherVm teacherVm) { Teacher teacher = new Teacher { Id = teacherVm.Id, Surname = teacherVm.Surname, Name = teacherVm.Name, Patronymic = teacherVm.Patronymic, Degree = teacherVm.Degree, AdditionalInfo = teacherVm.AdditionalInfo, PictureId = teacherVm.PictureId, }; _teacherDataSource.Update(teacher); return(_websiteDbContext.SaveChangesAsync()); }
public async Task <IActionResult> TeacherList(int Page = 1) { Int64 Count = 1; List <Teacher> tcr = await _context.Teacher.AsNoTracking().ToListAsync(); if (tcr == null) { return(RedirectToAction("Error")); } List <TeacherVm> tv = new List <TeacherVm>(); foreach (var item in tcr) { TeacherVm t = new TeacherVm() { TcridVM = item.TeacherId, TcrnameVM = item.TeacherName, TcrdesigVM = item.TeacherDesignation, TcrdobVM = item.TeacherDOB, TcrbgVM = item.TeacherBG, TcrgenderVM = item.TeacherGender, TcrjdVM = item.TeacherJD, TcrnationVM = item.TeacherNationality, TcrcaddrssVM = item.TeacherCAddress, TcrpaddrssVM = item.TeacherPAddress, TcrphotoVM = item.TeacherPhoto, TcrphoneVM = item.TeacherPhoneNo, TcremailVM = item.TeacherEmail, }; //Assinging the counter value of a element t.QlSLVM = Count; Count++; //Add the Teacher to the list tv.Add(t); } //Pass the List to the View var List = await tv.ToPagedListAsync(Page, 5); return(View(List)); }
public ActionResult AddTeacher(TeacherVm emp) { if (emp.Teacher.Id == 0) { absd.Tacehers.Add(emp.Teacher); absd.SaveChanges(); } else { var record = absd.Tacehers.SingleOrDefault(m => m.Id == emp.Teacher.Id); record.Id = emp.Teacher.Id; record.FirstName = emp.Teacher.FirstName; record.LastName = emp.Teacher.LastName; record.DateofBirth = emp.Teacher.DateofBirth; record.Phone = emp.Teacher.Phone; record.Address = emp.Teacher.Address; absd.SaveChanges(); } return(RedirectToAction("TeacherDetail")); }
public async Task <IActionResult> UpdateTeacher(TeacherVm tr, IFormFile image) { if (ModelState.IsValid) { Teacher tchr = new Teacher() { TeacherId = tr.TcridVM, TeacherName = tr.TcrnameVM, TeacherBG = tr.TcrbgVM, TeacherEmail = tr.TcremailVM, TeacherCAddress = tr.TcrcaddrssVM, TeacherPAddress = tr.TcrpaddrssVM, TeacherDOB = tr.TcrdobVM, TeacherGender = tr.TcrgenderVM, TeacherNationality = tr.TcrnationVM, TeacherPhoneNo = tr.TcrphoneVM, TeacherJD = tr.TcrjdVM, TeacherPhoto = tr.TcrphotoVM, TeacherDesignation = tr.TcrdesigVM }; //if (image == null) //{ // if (tr.TcrphotoVM != null) // { // var path = Path.Combine(_imagepath.WebRootPath + "/images"); // string filepath = Path.Combine(path, tr.TcrphotoVM); // System.IO.File.Delete(filepath); // tchr.TeacherPhoto = null; // } //} string un = null; if (image != null) { if (tr.TcrphotoVM != null) { /// Delete Existing Image var path = Path.Combine(_imagepath.WebRootPath + "/images"); string filepath = Path.Combine(path, tr.TcrphotoVM); if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); } tchr.TeacherPhoto = null; path = null; un = null; filepath = null; ///Update Image path = Path.Combine(_imagepath.WebRootPath + "/images"); un = Guid.NewGuid().ToString() + "_" + image.FileName; filepath = Path.Combine(path, un); using (var file = new FileStream(filepath, FileMode.Create)) { await image.CopyToAsync(file); } tchr.TeacherPhoto = un; } else { var path = Path.Combine(_imagepath.WebRootPath + "/images"); un = Guid.NewGuid().ToString() + "_" + image.FileName; string filepath = Path.Combine(path, un); using (var file = new FileStream(filepath, FileMode.Create)) { await image.CopyToAsync(file); } tchr.TeacherPhoto = un; } } _context.Teacher.Update(tchr); await _context.SaveChangesAsync(); ///Save the Document Information to the Database TeacherDocSubmitted doc = new TeacherDocSubmitted() { TeacherId = tr.TcridVM, TeacherDocSubmittedId = tr.DocSLVM, SSCCertificate = tr.TcrdocsubhsccrtfctVM, SSCMarksheet = tr.TcrdocsubsscmarkVM, HSCCertificate = tr.TcrdocsubhsccrtfctVM, HSCMarksheet = tr.TcrdocsubhscmarkVM, HonsCertificate = tr.TcrdocsubhonscrtfctVM, HonsMarksheet = tr.TcrdocsubhonsmarkVM }; _context.TeacherDocSubmitted.Update(doc); await _context.SaveChangesAsync(); TeacherQualification tq = new TeacherQualification() { TeacherQualificationId = tr.QlSLVM, TeacherId = tr.TcridVM, SSCYear = tr.TcrqsscyearVM, SSCGrade = tr.TcrqsscgradeVM, SSCInstitute = tr.TcrqsscinsVM, HSCYear = tr.TcrqhscyearVM, HSCGrade = tr.TcrqhscgradeVM, HSCInstitute = tr.TcrqhscinsVM, HonsYear = tr.TcrqhonsyearVM, HonsGrade = tr.TcrqhonsgradeVM, HonsInstitute = tr.TcrqhonsinsVM }; _context.TeacherQualification.Update(tq); await _context.SaveChangesAsync(); return(RedirectToAction("TeacherList")); } else { return(View()); } }
public async Task <IActionResult> AddTeacher(TeacherVm tr, IFormFile image) { if (ModelState.IsValid) { Teacher tchr = new Teacher() { TeacherId = 0, TeacherName = tr.TcrnameVM, TeacherBG = tr.TcrbgVM, TeacherEmail = tr.TcremailVM, TeacherCAddress = tr.TcrcaddrssVM, TeacherPAddress = tr.TcrpaddrssVM, TeacherDOB = tr.TcrdobVM, TeacherGender = tr.TcrgenderVM, TeacherNationality = tr.TcrnationVM, TeacherPhoneNo = tr.TcrphoneVM, TeacherJD = DateTime.Now.Date, TeacherPhoto = tr.TcrphotoVM, TeacherDesignation = tr.TcrdesigVM }; string un = null; if (image != null) { var path = Path.Combine(_imagepath.WebRootPath + "/images"); un = Guid.NewGuid().ToString() + "_" + image.FileName; string filepath = Path.Combine(path, un); using (var file = new FileStream(filepath, FileMode.Create)) { await image.CopyToAsync(file); } tchr.TeacherPhoto = un; } _context.Teacher.Add(tchr); await _context.SaveChangesAsync(); ///Get the id of teacher var TeacherId = tchr.TeacherId; //Teacher email var TeacherEmail = tchr.TeacherEmail; // Create random password PasswordGenerator ps = new PasswordGenerator(); //Create login Login lg = new Login() { LoginId = 0, Username = TeacherEmail, Password = ps.RandomPassword(), FirstLoginStatus = false, ActiveStatus = true, RoleId = 2, DistinguishId = TeacherId }; lg.CurrentPassword = lg.Password; _context.Login.Add(lg); await _context.SaveChangesAsync(); ///Save the Document Information to the Database TeacherDocSubmitted doc = new TeacherDocSubmitted() { TeacherId = TeacherId, TeacherDocSubmittedId = 0, SSCCertificate = tr.TcrdocsubhsccrtfctVM, SSCMarksheet = tr.TcrdocsubsscmarkVM, HSCCertificate = tr.TcrdocsubhsccrtfctVM, HSCMarksheet = tr.TcrdocsubhscmarkVM, HonsCertificate = tr.TcrdocsubhonscrtfctVM, HonsMarksheet = tr.TcrdocsubhonsmarkVM }; await _context.TeacherDocSubmitted.AddAsync(doc); await _context.SaveChangesAsync(); TeacherQualification tq = new TeacherQualification() { TeacherQualificationId = 0, TeacherId = TeacherId, SSCYear = tr.TcrqsscyearVM, SSCGrade = tr.TcrqsscgradeVM, SSCInstitute = tr.TcrqsscinsVM, HSCYear = tr.TcrqhscyearVM, HSCGrade = tr.TcrqhscgradeVM, HSCInstitute = tr.TcrqhscinsVM, HonsYear = tr.TcrqhonsyearVM, HonsGrade = tr.TcrqhonsgradeVM, HonsInstitute = tr.TcrqhonsinsVM }; await _context.TeacherQualification.AddAsync(tq); await _context.SaveChangesAsync(); ///Clear the model state ModelState.Clear(); return(View()); } return(View()); }
public async Task <IActionResult> UpdateTeacher(Int64 id) { var tcr = await _context.Teacher.Where(s => s.TeacherId == id).ToListAsync(); if (tcr.Count != 0) { var doc = await _context.TeacherDocSubmitted.Where(s => s.TeacherId == id).ToListAsync(); if (doc.Count != 0) { var ql = await _context.TeacherQualification.Where(s => s.TeacherId == id).ToListAsync(); if (ql.Count != 0) { var query = (from t in tcr join d in doc on t.TeacherId equals d.TeacherId join q in ql on t.TeacherId equals q.TeacherId where t.TeacherId == id select new { //Teacher Information Tcrid = t.TeacherId, Tcrname = t.TeacherName, Tcrdesig = t.TeacherDesignation, Tcrdob = t.TeacherDOB, Tcrbg = t.TeacherBG, Tcrgender = t.TeacherGender, Tcrjd = t.TeacherJD, Tcrnation = t.TeacherNationality, Tcrcaddrss = t.TeacherCAddress, Tcrpaddrss = t.TeacherPAddress, Tcrphoto = t.TeacherPhoto, Tcrphone = t.TeacherPhoneNo, Tcremail = t.TeacherEmail, //Teacher Document Submission Tcrdocsubsscmark = d.SSCMarksheet, Tcrdocsubssccrtfct = d.SSCCertificate, Tcrdocsubhscmark = d.HSCMarksheet, Tcrdocsubhsccrtfct = d.HSCCertificate, Tcrdocsubhonsmark = d.HonsMarksheet, Tcrdocsubhonscrtfct = d.HonsCertificate, TcrDocSL = d.TeacherDocSubmittedId, //Teacher Qualifiaction Tcrqsscyear = q.SSCYear, Tcrqhscyear = q.HSCYear, Tcrqhonsyear = q.HonsYear, Tcrqsscgrade = q.SSCGrade, Tcrqhscgrade = q.HSCGrade, Tcrqhonsgrade = q.HonsGrade, Tcrqsscins = q.SSCInstitute, Tcrqhscins = q.HonsInstitute, Tcrqhonsins = q.HonsInstitute, TcrQSL = q.TeacherQualificationId }).FirstOrDefault(); TeacherVm tr = new TeacherVm() { TcridVM = query.Tcrid, TcrnameVM = query.Tcrname, TcrdesigVM = query.Tcrdesig, TcrdobVM = query.Tcrdob, TcrbgVM = query.Tcrbg, TcrgenderVM = query.Tcrgender, TcrjdVM = query.Tcrjd, TcrnationVM = query.Tcrnation, TcrcaddrssVM = query.Tcrcaddrss, TcrpaddrssVM = query.Tcrpaddrss, TcrphotoVM = query.Tcrphoto, TcrphoneVM = query.Tcrphone, TcremailVM = query.Tcremail, //Teacher Document Submission TcrdocsubsscmarkVM = query.Tcrdocsubsscmark, TcrdocsubssccrtfctVM = query.Tcrdocsubssccrtfct, TcrdocsubhscmarkVM = query.Tcrdocsubhscmark, TcrdocsubhsccrtfctVM = query.Tcrdocsubhsccrtfct, TcrdocsubhonsmarkVM = query.Tcrdocsubhonsmark, TcrdocsubhonscrtfctVM = query.Tcrdocsubhonscrtfct, DocSLVM = query.TcrDocSL, //Teacher Qualifiaction Submission TcrqsscyearVM = query.Tcrqsscyear, TcrqhscyearVM = query.Tcrqhscyear, TcrqhonsyearVM = query.Tcrqhonsyear, TcrqsscgradeVM = query.Tcrqsscgrade, TcrqhscgradeVM = query.Tcrqhscgrade, TcrqhonsgradeVM = query.Tcrqhonsgrade, TcrqsscinsVM = query.Tcrqsscins, TcrqhscinsVM = query.Tcrqhscins, TcrqhonsinsVM = query.Tcrqhonsins, QlSLVM = query.TcrQSL, }; return(View(tr)); } else { return(RedirectToAction("Error")); } } else { return(RedirectToAction("Error")); } } else { return(RedirectToAction("Error")); } }