public async Task <IActionResult> Get() { using (SqlConnection conn = Connection) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = @"select Instructors.id, Instructors.FirstName, Instructors.LastName, instructors.SlackHandle, cohort.[Name] from Instructors left join cohort on Instructors.CohortId = cohort.id"; SqlDataReader reader = cmd.ExecuteReader(); List <Instructors> AllInstructors = new List <Instructors>(); while (reader.Read()) { Instructors instructor = new Instructors { id = reader.GetInt32(reader.GetOrdinal("id")), FirstName = reader.GetString(reader.GetOrdinal("FirstName")), LastName = reader.GetString(reader.GetOrdinal("LastName")), slackHandle = reader.GetString(reader.GetOrdinal("slackHandle")), CohortName = reader.GetString(reader.GetOrdinal("Name")) }; AllInstructors.Add(instructor); } reader.Close(); return(Ok(AllInstructors)); } } }
public Instructors Add(string firstName, string middleName, string lastName, string organization) { var instructor = new Instructors(); instructor.FirstName = firstName; instructor.MiddleName = middleName; instructor.LastName = lastName; instructor.Organization = organization; var existingInstructor = db.Instructors.FirstOrDefault(q => q.FirstName == firstName && q.MiddleName == middleName && q.LastName == lastName && q.Organization == organization); if (existingInstructor == null) { db.Instructors.Add(instructor); db.SaveChanges(); } else { instructor = existingInstructor; } return(instructor); }
public async Task <IActionResult> Edit(int id, [Bind("InstructorId,FirstName,LastName,EmailAddress,CourseName")] Instructors instructors, Courses course) { if (id != instructors.InstructorId) { return(NotFound()); } if (ModelState.IsValid) { try { if (course != null) { var newCourse = _context.Courses.Where(c => c.CourseID == course.CourseID).SingleOrDefault(); instructors.Courses = newCourse; } _context.Update(instructors); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InstructorsExists(instructors.InstructorId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(instructors)); }
// GET: Contact public ActionResult Instructor(int id) { db_connect(); string stm = "SELECT * FROM instructors WHERE Id=" + id + ";"; cmd = new MySqlCommand(stm, dbConnection); Instructors instructor = new Instructors(); try { MySqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { instructor.Id = rdr.GetInt32(0); instructor.Name = rdr.GetString(1); instructor.Email = rdr.GetString(2); instructor.Address = rdr.GetString(3); instructor.Level = rdr.GetString(4); instructor.Facebook = rdr.GetString(5); } ViewBag.instructor = instructor; } catch (Exception e) { Debug.WriteLine(e.Message); } return(View()); }
public override void Seed() { System.Diagnostics.Debug.Print("Seeding db"); var instructor1 = Instructors.Add(new Instructor { ID = 10, IsDeleted = true, HireDate = new DateTime(2015, 2, 1) }); var instructor2 = Instructors.Add(new Instructor { ID = 11, IsDeleted = false, HireDate = new DateTime(2015, 2, 2) }); var instructor3 = Instructors.Add(new Instructor { ID = 12, IsDeleted = false, HireDate = new DateTime(2015, 2, 3) }); Students.Add(new Student { ID = 1, IsDeleted = false, EnrollmentDate = new DateTime(2015, 1, 1), Instructor = instructor1 }); Students.Add(new Student { ID = 2, IsDeleted = true, EnrollmentDate = new DateTime(2015, 1, 2), Instructor = instructor2 }); Students.Add(new Student { ID = 3, IsDeleted = false, EnrollmentDate = new DateTime(2015, 1, 3), Instructor = instructor3 }); SaveChanges(); }
public List <SelectListItem> GetInstructorList(ILocalizationManager localizationManager) { var list = new List <SelectListItem> { new SelectListItem { Text = localizationManager.GetString(CRSConsts.LocalizationSourceName, "PleaseSelect"), Value = "", Selected = InstructorCode == null } }; var instructorList = Instructors.ToList(); list.AddRange(instructorList .Select(instructor => new SelectListItem { Text = instructor.Name.ToString(), Value = instructor.Code.ToString(), Selected = instructor.Equals(InstructorCode) }) ); return(list); }
public async Task <IActionResult> PostInstructors([FromBody] Instructors instructors) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Instructors.Add(instructors); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (InstructorsExists(instructors.Id)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetInstructors", new { id = instructors.Id }, instructors)); }
public override void Seed() { System.Diagnostics.Debug.Print("Seeding db"); var instructor1 = Instructors.Add(new Instructor { ID = 10, IsDeleted = true, HireDate = new DateTime(2015, 2, 1) }); var instructor2 = Instructors.Add(new Instructor { ID = 11, IsDeleted = false, HireDate = new DateTime(2015, 2, 2) }); var instructor3 = Instructors.Add(new Instructor { ID = 12, IsDeleted = false, HireDate = new DateTime(2015, 2, 3) }); Students.Add(new Student { ID = 1, IsDeleted = false, EnrollmentDate = new DateTime(2015, 1, 1), Instructor = instructor1 }); Students.Add(new Student { ID = 2, IsDeleted = true, EnrollmentDate = new DateTime(2015, 1, 2), Instructor = instructor2 }); Students.Add(new Student { ID = 3, IsDeleted = false, EnrollmentDate = new DateTime(2015, 1, 3), Instructor = instructor3 }); Residents.Add(new Resident { Created = new DateTime(2015, 1, 1), CreatedBy = "me", Id = 1, FirstName = "Fred", LastName = "Flintstone", Title = "Mr", FamiliarName = "Fred", Gender = "M" }); Residents.Add(new Resident { Created = new DateTime(2015, 2, 1), CreatedBy = "me", Deleted = new DateTime(2015, 2, 3), Id = 2, FirstName = "Barney", LastName = "Rubble", Title = "Mr", FamiliarName = "Barney", Gender = "M" }); SaveChanges(); }
public async Task <IActionResult> PutInstructors([FromRoute] int id, [FromBody] Instructors instructors) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != instructors.Id) { return(BadRequest()); } _context.Entry(instructors).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InstructorsExists(id)) { return(NotFound()); } else { throw; } } return(Ok(instructors)); }
public List <Instructors> Instructors() { List <Instructors> list = null; DataProvider.ExecuteCmd(GetConnection, "dbo.Instructors_SelectAll" , inputParamMapper : null , map : delegate(IDataReader reader, short set) { Instructors In = new Instructors(); int startingIndex = 0; In.Id = reader.GetSafeInt32(startingIndex++); In.Name = reader.GetSafeString(startingIndex++); In.Email = reader.GetSafeString(startingIndex++); In.Bio = reader.GetSafeString(startingIndex++); In.LinkedIn = reader.GetSafeString(startingIndex++); In.CoursesTaught = reader.GetSafeString(startingIndex++); if (list == null) { list = new List <Instructors>(); } list.Add(In); } ); return(list); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Fname,Lname,NumClasses")] Instructors instructors) { if (id != instructors.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(instructors); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InstructorsExists(instructors.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(instructors)); }
public ResultSvc <Instructor> CreateInstructor(Instructor instructor) { var result = new ResultSvc <Instructor>(instructor); try { if (!Instructors.Items.Any(x => x.Firstname == instructor.Firstname.Trim() && x.Lastname == instructor.Lastname.Trim() && (!string.IsNullOrEmpty(instructor.Title) && x.Title == instructor.Title.Trim()))) { instructor.Firstname = instructor.Firstname?.Trim(); instructor.Lastname = instructor.Lastname?.Trim(); instructor.Title = instructor.Title?.Trim(); instructor.Description = instructor.Description?.Trim(); instructor.Email = instructor.Email?.Trim(); instructor.Phone = instructor.Phone?.Trim(); instructor.Facebook = instructor.Facebook?.Trim(); instructor.UserCreatedId = Context.HttpContext.User.GetUserId(); Instructors.Add(instructor); } else { result.Errors.Add("Tento instruktor již existuje!"); } } catch (Exception e) { Logger.LogError(e.Message); } return(result); }
//creates a number of instructors public static void CreateInstructors(int count) { List <Town> towns = Towns.GetTowns(); Random rnd = new Random(); for (int i = 0; i < count; i++) { Town town = towns[rnd.Next(towns.Count)]; DateTime birthdate = MathHelpers.GetRandomDate(GameObject.GetInstance().GameTime.AddYears(-Pilot.RetirementAge), GameObject.GetInstance().GameTime.AddYears(-23)); PilotProfile profile = new PilotProfile(Names.GetInstance().getRandomFirstName(town.Country), Names.GetInstance().getRandomLastName(town.Country), birthdate, town); Dictionary <PilotRating, int> rankings = new Dictionary <PilotRating, int>(); rankings.Add(PilotRatings.GetRating("A"), 10); rankings.Add(PilotRatings.GetRating("B"), 20); rankings.Add(PilotRatings.GetRating("C"), 40); rankings.Add(PilotRatings.GetRating("D"), 20); rankings.Add(PilotRatings.GetRating("E"), 10); PilotRating ranking = AIHelpers.GetRandomItem <PilotRating>(rankings); Instructor instructor = new Instructor(profile, ranking); Instructors.AddInstructor(instructor); } }
public ActionResult DeleteConfirmed(string id) { Instructors instructors = db.Instructors.Find(id); db.Instructors.Remove(instructors); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Register(JoinViewModel model) { if (ModelState.IsValid) { var user = (ApplicationUser)null; var UserAccessType = Request.Form["item"]; if (UserAccessType == "Student") { user = new Student { Name = model.Name, UserName = model.Name, Email = model.Email, Address = model.Address, BD = model.BirthDate, GradeOfAbsence = 600, NoOfAbsenceDay = 0, NoOfPermissions = 0, UserAccessType = "Student" }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Student , Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); var RoleAssigner = UserManager.AddToRole(user.Id, "Student"); TempData["Student"] = user; return(RedirectToAction("Index", "Home")); } AddErrors(result); } else if (UserAccessType == "Instructor") { user = new Instructors { Name = model.Name, UserName = model.Name, Email = model.Email, Address = model.Address, BD = model.BirthDate, UserAccessType = "Instructor" }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(user.Id, "Instructor , Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); var RoleAssigner = UserManager.AddToRole(user.Id, "Instructor"); TempData["Instructor"] = user; return(RedirectToAction("Index", "Home")); } AddErrors(result); } } // If we got this far, something failed, redisplay form return(View(model)); }
private async void btn_delete_Click(object sender, RoutedEventArgs e) { if (await this.ShowMessageAsync("Are you sure", "You're deleting an instructor, are you sure you want to do that?", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative) { Instructors.RemoveInstructor(EditedInstructor); Globals.RefreshReferenceInformation(); this.Close(); } }
//shwos the list of instructors private void showInstructors() { lbInstructors.Items.Clear(); foreach (Instructor instructor in Instructors.GetUnassignedInstructors().OrderByDescending(i => i.Profile.Age)) { lbInstructors.Items.Add(instructor); } }
public async Task <IActionResult> Edit(int id, [Bind("CourseInstanceId,Name,Description,Department,Number,Semester,Year,StatusId,DueDate")] CourseInstance courseInstance, string[] newInstructors) { if (id != courseInstance.CourseInstanceId) { return(NotFound()); } if (ModelState.IsValid) { try { if (newInstructors != null) { List <Instructors> currentCourseInstructors = _context.Instructors.Include(i => i.User).Where(i => i.CourseInstanceId == courseInstance.CourseInstanceId).ToList(); //Remove current instructors foreach (Instructors currentInst in currentCourseInstructors) { _context.Instructors.Remove(currentInst); } foreach (string newInstructor in newInstructors) { //Find selected instructor UserLocator instructorUserLoc = _context.UserLocator.Where(u => u.UserLoginEmail == newInstructor).FirstOrDefault(); if (instructorUserLoc != null) //User must exist { Instructors newInst = new Instructors() { CourseInstanceId = courseInstance.CourseInstanceId, UserId = instructorUserLoc.Id }; _context.Instructors.Add(newInst); } } } _context.Update(courseInstance); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseInstanceExists(courseInstance.CourseInstanceId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } //ViewData["CourseInstanceId"] = new SelectList(_context.CourseInstance, "CourseInstanceId", "Department", courseInstance.CourseInstanceId); //return View(courseInstance); return(View(new CourseEditData() { Course = _context.CourseInstance.Where(c => c.CourseInstanceId == id).Include(c => c.Instructors).ThenInclude(i => i.User).FirstOrDefault(), Departments = _context.Departments, CourseStatus = _context.CourseStatus, Professors = GetInstructors() })); }
public ActionResult Edit([Bind(Include = "InstructorID,InstructorFname,InstructorLname,InstructorPhone,InstructorHireDate")] Instructors instructors) { if (ModelState.IsValid) { db.Entry(instructors).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(instructors)); }
public ActionResult Edit([Bind(Include = "instructorID,firstName,lastName,email,startDate")] Instructors instructors) { if (ModelState.IsValid) { db.Entry(instructors).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(instructors)); }
public async Task <IActionResult> CreateSampleFile(int?courseId, int?emId, int score, IFormFile sample) { if (courseId == null || emId == null || sample == null) { return(Json(new { success = false })); } //Verify instructor (course must not be archived) CourseInstance course = _context.CourseInstance.Include(c => c.Instructors).ThenInclude(i => i.User) .Where(c => c.CourseInstanceId == courseId && c.Status.Status != CourseStatusNames.Archived).FirstOrDefault(); if (course == null) { return(Json(new { success = false })); } Instructors inst = course.Instructors.Where(i => i.User.UserLoginEmail == User.Identity.Name).FirstOrDefault(); if (inst == null) { return(Json(new { success = false })); } EvaluationMetrics emObj = _context.EvaluationMetrics.Include(e => e.Lo).ThenInclude(l => l.CourseInstance) .Where(e => e.Emid == emId && e.Lo.CourseInstance.Instructors.Contains(inst)).FirstOrDefault(); if (emObj == null) { return(Json(new { success = false })); } int?sfid = null; if (sample != null) { string filename = sample.FileName; if (sample.Length > 0) { using (var stream = new MemoryStream()) { await sample.CopyToAsync(stream); SampleFiles sf = new SampleFiles() { Score = score, FileName = sample.FileName, ContentType = sample.ContentType, FileContent = stream.ToArray(), Em = emObj }; _context.SampleFiles.Add(sf); _context.SaveChanges(); sfid = sf.Sid; } } } return(RedirectToAction("SampleFile", new { sfId = sfid })); }
public bool CreateInstructor(Instructor instructor, string userId) { try { if (!Instructors.Items.Any(x => x.Firstname == instructor.Firstname.Trim() && x.Surname == instructor.Surname.Trim())) { instructor.Firstname = instructor.Firstname.Trim(); instructor.Surname = instructor.Surname.Trim(); instructor.UserCreated = userId; instructor.Order = Instructors.Items.Select(x => x.Order).DefaultIfEmpty(0).Max() + 1; foreach (var l in instructor.Languages) { l.LanguageLevel = LanguageLevels.FindById(l.LanguageLevelId); } var languages = new List <InstructorLanguage>(instructor.Languages); foreach (var l in languages) { if (instructor.Languages.Any(x => x.LanguageId == l.LanguageId && x.LanguageLevel.Level > l.LanguageLevel.Level)) { instructor.Languages.Remove(l); } } foreach (var e in instructor.Expertises) { e.ExpertiseLevel = ExpertiseLevels.FindById(e.ExpertiseLevelId); } var expertises = new List <InstructorExpertise>(instructor.Expertises); foreach (var e in expertises) { if (instructor.Expertises.Any(x => x.ExpertiseId == e.ExpertiseId && x.ExpertiseLevel.Level > e.ExpertiseLevel.Level)) { instructor.Expertises.Remove(e); } } foreach (var ticket in instructor.Tickets) { ticket.From = ticket.From.Date; ticket.To = ticket.To.Date; } Instructors.Add(instructor); return(true); } } catch (Exception e) { } return(false); }
public ActionResult Create([Bind(Include = "instructorID,firstName,lastName,email,startDate")] Instructors instructors) { if (ModelState.IsValid) { db.Instructors.Add(instructors); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(instructors)); }
public ActionResult Create([Bind(Include = "InstructorID,InstructorFname,InstructorLname,InstructorPhone,InstructorHireDate")] Instructors instructors) { if (ModelState.IsValid) { db.Instructors.Add(instructors); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(instructors)); }
public async Task <IActionResult> Create([Bind("Id,Fname,Lname,NumClasses")] Instructors instructors) { if (ModelState.IsValid) { _context.Add(instructors); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(instructors)); }
static void AddOrUpdateInstructor(string courseTitle, string instructorName) { var course = Courses.SingleOrDefault(c => c.Title == courseTitle); var inst = course.Instructors.SingleOrDefault(i => i.LastName == instructorName); if (inst == null) { var instructor = Instructors.Single(i => i.LastName == instructorName); course.Instructors.Add(instructor); } }
public PageFlightSchools() { this.AllInstructors = new ObservableCollection <Instructor>(); this.FlightSchools = new ObservableCollection <FlightSchool>(); Instructors.GetUnassignedInstructors().ForEach(i => this.AllInstructors.Add(i)); GameObject.GetInstance().HumanAirline.FlightSchools.ForEach(f => this.FlightSchools.Add(f)); this.Loaded += PageFlightSchools_Loaded; InitializeComponent(); }
public IActionResult Update(string id, Instructors instructorIn) { var instructor = _instructorsService.Get(id); if (instructor == null) { return(NotFound()); } _instructorsService.Update(id, instructorIn); return(NoContent()); }
private void LoadDepartments() { Departments.Clear(); foreach (var department in db.GetDepartments()) { var departmentView = new DepartmentView() { Department = department, Head = Instructors.FirstOrDefault(instructor => instructor.Id == department.HeadInstructorId) }; Departments.Add(departmentView); } }
// GET: Instructors/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Instructors instructors = db.Instructors.Find(id); if (instructors == null) { return(HttpNotFound()); } return(View(instructors)); }