/// <summary> /// Prepare professor model /// </summary> /// <param name="model">Professor model</param> /// <param name="professor">Professor</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Professor model</returns> public virtual ProfessorModel PrepareProfessorModel(ProfessorModel model, Professor professor, bool excludeProperties = false) { if (professor != null) { //fill in model values from the entity model = model ?? professor.ToModel <ProfessorModel>(); model.Id = professor.Id; model.ProfessorCode = professor.ProfessorCode; model.TitleId = professor.TitleId; model.TitleName = professor.TitleName; model.FirstName = professor.FirstName; model.LastName = professor.LastName; model.Telephone = professor.Telephone; model.Email = professor.Email; model.ProfessorType = professor.ProfessorType; model.ProfessorTypeName = professor.ProfessorType.Equals("InternalExpert") ? "ผู้ทรงคุณวุฒิภายใน" : "ผู้ทรงคุณวุฒิภายนอก"; model.IsActive = professor.IsActive; PrepareAddressModel(model.AddressModel, professor); } else { model.ProfessorCode = _professorService.GetNextNumber(); model.ProfessorType = ProfessorType.InternalExpert.ToString(); model.IsActive = true; } PrepareAddressModel(model.AddressModel, professor); _baseAdminModelFactory.PrepareTitles(model.AvailableTitles, true, "--ระบุคำนำหน้าชื่อ--"); //Default Thailand return(model); }
public void UpdateObservation(int ProfessorId, string observacoes) { using (ProfessorModel model = new ProfessorModel()) { model.UpdateObservation(ProfessorId, observacoes); } }
//********** AJAX METHODS **********// //***** Message TAs AJAX ***** (made from Professor ViewTAs View Page) public JsonResult MessageTAs(string TAs, string text) { string response = "Unable to message TAs sepcified."; ProfessorModel user = Cache.GetUser <ProfessorModel>(); if (user == null) { response = "Issue obtaining account details. Please sign out and back in again."; } List <string> Ids = TAs.Split(',').ToList(); if (Ids != null && Ids.Count > 0 && !String.IsNullOrWhiteSpace(text) && user != null) { foreach (string TA_Id in Ids) { if (Int32.TryParse(TA_Id, out int Id)) { DB.Message message = new DB.Message(); message.TeachersAssistantId = Id; message.SenderType = "Professor"; message.SenderName = $"{user.FirstName} {user.LastName}"; message.SenderEmail = user.Login.Username; message.Text = text; string errors = DB.DBMethods.Insert(message); } } Response.StatusCode = (int)HttpStatusCode.OK; return(Json("Success", MediaTypeNames.Text.Plain)); } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(response, MediaTypeNames.Text.Plain)); }
public JsonResult AddCourse(DB.Course course) { string message = "Failed to Add Course"; if (course != null && course.SLN != 0 && Int32.TryParse(course.Term, out int term)) { if (DB.DBMethods.Course_Get(course.SLN) == null) { course.Term = EnumValues.Terms[term - 1]; ProfessorModel user = null; if ((user = Cache.GetUser <ProfessorModel>()) != null) { if (!String.IsNullOrWhiteSpace(DB.DBMethods.Insert(course))) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json("Failed to Add Course.", MediaTypeNames.Text.Plain)); } user.Courses.Add(course); Cache.Set(user); } else { Courses.Add(course); } Response.StatusCode = (int)HttpStatusCode.OK; return(Json("Success", MediaTypeNames.Text.Plain)); } message = "That Course has already been assigned to another professor in our Database.\nPlease try another course."; } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(message, MediaTypeNames.Text.Plain)); }
public async Task <IActionResult> Edit(int id, [Bind("PId,Name,PaperworkNumber,Unit,Major,PhoneNumber,Email,WeChat,CardNumber,BankName,Password,Salt,Type")] ProfessorModel professorModel) { if (id != professorModel.PId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(professorModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProfessorModelExists(professorModel.PId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(professorModel)); }
public void Post([FromBody] ProfessorModel professor) { { var dbm = new DatabaseManager(); dbm.AddProfessor(professor.Professor_Name, professor.username, professor.password); } }
public ProfessorRequest CarregarRequest() { ProfessorRequest professorReq = new ProfessorRequest(); ProfessorModel _professor = new ProfessorModel(); LoginModel login = new LoginModel(); _professor.NrAnoPrimeiroEmprego = Convert.ToInt32(nudPrimeiroEmprego.Value); _professor.DtFaculdadeInicio = dtpFaculdadeInicio.Value; _professor.DtFaculdadeFim = dtpFaculdadeFim.Value; _professor.DtNascimento = dtpNascimento.Value; _professor.TpContratacao = cboContrato.Text; _professor.DsRgEmissor = txtRGEmissao.Text; _professor.DsFaculdade = txtFaculdade.Text; _professor.DsTelefone = txtTelefone.Text; _professor.DsEstado = txtEstadoNasc.Text; _professor.DsCvLattes = txtCvLattes.Text; _professor.DsCelular = txtCelular.Text; _professor.DsRgOrgao = txtRGOrgao.Text; _professor.BtAtivo = chkAtivo.Checked; _professor.NmProfessor = txtNome.Text; _professor.DsCurso = txtCurso.Text; _professor.DsEmail = txtEmail.Text; _professor.NmMae = txtNome.Text; _professor.DsCpf = txtCpf.Text; _professor.NmPai = txtPai.Text; login.DsLogin = txtLogin.Text; _professor.DsRg = txtRG.Text; professorReq.Professor = _professor; professorReq.Login = login; return(professorReq); }
public JsonResult RemoveCourse(string SLN) { ProfessorModel user = null; if ((user = Cache.GetUser <ProfessorModel>()) != null) { if (SLN != null && Int32.TryParse(SLN, out int Id)) { if (DB.DBMethods.Delete_Course(Id)) { DB.Course course = user.Courses.FirstOrDefault(x => x.Id == Id); user.Courses.Remove(course); Cache.Set(user); Response.StatusCode = (int)HttpStatusCode.OK; return(Json("Success", MediaTypeNames.Text.Plain)); } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json("Failed to Remove Course.", MediaTypeNames.Text.Plain)); } } else if (SLN != null && Int32.TryParse(SLN, out int SLN_Num)) { DB.Course course = Courses.FirstOrDefault(x => x.SLN == SLN_Num); Courses.Remove(course); Response.StatusCode = (int)HttpStatusCode.OK; return(Json("Success", MediaTypeNames.Text.Plain)); } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json("Failed to Remove Course Infomation", MediaTypeNames.Text.Plain)); }
public IActionResult AddCourse(CourseModel newCrse) { // MUST USE INCLUDE SO THAT NEW COURSE CAN BE ADDED TO MATCHING PROFESSOR ProfessorModel matchingProf = _context.professors.Include(prof => prof.currentCourses).FirstOrDefault(prof => prof.id == newCrse.professorID); // if matching prof is found if (matchingProf != null) { // if object passes model validation if (ModelState.IsValid) { // add to list and db matchingProf.currentCourses.Add(newCrse); _context.courses.Add(newCrse); _context.SaveChanges(); return(RedirectToAction("Index")); } else // if model doesn't pass model validation { // display form again with invalid info return(View("CreateCourse", newCrse)); } } else // if matching prof is not found { return(Content("No matching professor Found")); } }
public ActionResult Login(LoginInfo info) { switch (info.User) { case UserType.TA: DB.TeachersAssistant TA_DB = DB.DBMethods.TA_HasAccount(info.Username, info.Password); if (TA_DB != null) { TAModel TA_Model = DB.DBMethods.TA_DBToModel(TA_DB); if (TA_Model != null) { Cache.Set(TA_Model); return(RedirectToAction(actionName: "Index", controllerName: "TA")); } } break; case UserType.Professor: DB.Professor Prof_DB = DB.DBMethods.Prof_HasAccount(info.Username, info.Password); if (Prof_DB != null) { ProfessorModel Prof_Model = DB.DBMethods.Prof_DBToModel(Prof_DB); if (Prof_Model != null) { Cache.Set(Prof_Model); return(RedirectToAction(actionName: "Index", controllerName: "Professor")); } } break; } ModelState.Clear(); return(RedirectToAction(actionName: "Login", controllerName: "Home", routeValues: new { notification = "Invalid Username and/or Password" })); }
//***** ViewTAs ***** public ActionResult ViewTAs(string Id, string prefix, string number, string notification = "") { //Ensures the Professor is still logged in ProfessorModel user = null; if ((user = Cache.GetUser <ProfessorModel>()) == null) { return(RedirectToAction(actionName: "SignOut", controllerName: "Home")); } if (Int32.TryParse(Id, out int id) && !string.IsNullOrWhiteSpace(prefix) && !string.IsNullOrWhiteSpace(number)) { //Creates a generic object containing all important info for 'ChooseTAs' View TAOptions options = new TAOptions() { CourseId = id, CourseName = $"{prefix} {number}", Notifications = notification }; DB.Course course = user.Courses != null?user.Courses.FirstOrDefault(x => x.Id == id) : null; if (course != null && course.TAs != null && course.TAs.Count > 0) { options.TAs = course.TAs.ToList(); } user.Notifications = notification; return(View(options)); } return(RedirectToAction(actionName: "Index", controllerName: "Professor")); }
//***** ACCOUNT DETAILS ***** public ActionResult AccountDetails(UserType user) { switch (user) { //Goes to the account details page in the Professor Controller case UserType.Professor: ProfessorModel Prof = Cache.GetUser <ProfessorModel>(); if (Prof == null) { break; } return(RedirectToAction(actionName: "AccountDetails", controllerName: "Professor")); //Goes to the account details page in the TA Controller case UserType.TA: TAModel TA = Cache.GetUser <TAModel>(); if (TA == null) { break; } return(RedirectToAction(actionName: "AccountDetails", controllerName: "TA")); default: break; } //If there was an issue all data is reset by sending user to signout page return(RedirectToAction(actionName: "SignOut", controllerName: "Home")); }
public ActionResult CreateProfessor(ProfessorModel professor) { _context.professorDb.Add(professor); _context.SaveChanges(); return(RedirectToAction("ListProfessors", "Admin")); }
public ProfessorModel GetProfessorUser(string username) { var queryString = string.Format("SELECT Professor_Name, Professor_ID, username, password FROM Professors WHERE username = '******'", username); var professor = new ProfessorModel(); sqlConnection1.Open(); var reader = GetDatabaseResults(queryString); if (reader.HasRows) { while (reader.Read()) { var Professor_Name = reader.GetString(0); var Professor_ID = reader.GetInt32(1); var user = reader.GetString(2); var password = reader.GetString(3); professor = new ProfessorModel { Professor_Name = Professor_Name, Professor_ID = Professor_ID, username = user, password = password }; } } sqlConnection1.Close(); return(professor); }
public ActionResult DeleteConfirmed(int id) { ProfessorModel professor = db.Professores.Find(id); db.Professores.Remove(professor); db.SaveChanges(); return(RedirectToAction(nameof(Index))); }
private void _updateProf(ProfessorModel prof) { _info.LastNameToProfessor[prof.Department][prof.LastName] = prof; _info.FirstNameToProfessor[prof.Department][prof.FirstName] = prof; _info.NameToProfessor[prof.Department][prof.FirstName + " " + prof.LastName] = prof; _info.NNumberToProfessor[prof.Department][prof.NNumber] = prof; _info.NNumbers.Add(prof.NNumber); }
public ActionResult Update(int id) { using (ProfessorModel model = new ProfessorModel()) { Professor p = model.Read(id); return(View(p)); } }
public ActionResult Steps() { using (ProfessorModel model = new ProfessorModel()) { List <Professor> lista = model.Read(); ViewBag.ListProfessor = lista; return(View()); } }
// Carrega a lista de professores public ActionResult Assignment() { using (ProfessorModel model = new ProfessorModel()) { List <Professor> listaProf = model.Read(); ViewBag.ListProfessor = listaProf; return(View()); } }
public ActionResult Edit(ProfessorModel professor) { if (ModelState.IsValid) { db.Entry(professor).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(professor)); }
public ActionResult Create(ProfessorModel Professor) { if (ModelState.IsValid) { db.Professor.Add(Professor); db.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(Professor)); }
public ActionResult editProfessorProfile(short id) { if (Session["username"] != null && Session["role"].Equals("professor")) { ProfessorModel professor = _context.professorDb.Find(id); return(View(professor)); } return(RedirectToAction("Index", "Home")); }
public Task AddAsync(ProfessorModel prof) => _info.Lock.Write(() => { if (_info.NNumbers.Contains(prof.NNumber)) { return(Task.CompletedTask); } _updateProf(prof); _context.Add(prof); return(Task.CompletedTask); });
//***** HOME PAGE ***** public ActionResult Index(string notification = "") { //Checks that a valid Professor account is cached in the browser's memory ProfessorModel user = null; if ((user = Cache.GetUser <ProfessorModel>()) == null) { return(RedirectToAction(actionName: "SignOut", controllerName: "Home")); } return(View(user)); }
public ActionResult Create() { // Abre a conexão em model using (ProfessorModel model = new ProfessorModel()) { // inserir método // Tipo de dado dinamico -- vai conter todos os professores cadastrados ViewBag.Professores = model.Read(); } // fecha conexao return(View()); }
public async Task <IActionResult> Create([Bind("PId,Name,PaperworkNumber,Unit,Major,PhoneNumber,Email,WeChat,CardNumber,BankName,Password,Salt,Type")] ProfessorModel professorModel) { if (ModelState.IsValid) { _context.Add(professorModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(professorModel)); }
//***** Edit Courses PAGE***** public ActionResult EditCourses(string notification = "") { //Checks if a TAModal instance exist in the browser's cached data ProfessorModel user = null; if ((user = Cache.GetUser <ProfessorModel>()) == null) { return(RedirectToAction(actionName: "SignOut", controllerName: "Home")); } user.Notifications = notification; return(View(user)); }
public ActionResult viewCourses() { if (Session["username"] != null && Session["role"].Equals("professor")) { short id = (short)Session["id"]; ProfessorModel professor = _context.professorDb.Where(p => p.id == id).Single(); var CoursesOfProfessor = professor.courseModel.ToList(); return(View(CoursesOfProfessor)); } return(RedirectToAction("Login", "Home")); }
public ActionResult listCoursesToShowGrades() { if (Session["username"] != null && Session["role"].Equals("professor")) { var professorId = (short)Session["id"]; ProfessorModel professor = _context.professorDb.Find(professorId); var courses = professor.courseModel.ToList(); return(View(courses)); } return(RedirectToAction("login", "Home")); }
// GET: professors public ActionResult Index() { using (ProfessorModel model = new ProfessorModel()) { List <Professor> lista = model.Read(); if (ctrlDelete) { ctrlDelete = false; ViewBag.Erro = "Could not remove this teacher because he has ties to the subjects"; } return(View(lista)); } }