public ActionResult <CourseInstructor> PostCourseInstructor(CourseInstructor model) { db.CourseInstructor.Add(model); db.SaveChanges(); return(Created("/api/CourseInstructor", model)); }
//Create a new Instructor and assign instructor to the Course private static void Q1() { string menu1 = "Please enter new instructor First Name"; string instruFirstName = AskInput(menu1); string menu2 = "Please enter new instructor Last Name"; string instruLastName = AskInput(menu2); var newInstructor = new Person(); newInstructor.FirstName = instruFirstName; newInstructor.LastName = instruLastName; db.Person.Add(newInstructor); db.SaveChanges(); listData.ListCourse(); string menu6 = "Please Choose the CourseID to be assigned"; string courseID = AskInput(menu6); CourseInstructor newCI = new CourseInstructor(); newCI.CourseID = short.Parse(courseID); var person = db.Person.Where(p => p.FirstName == instruFirstName & p.LastName == instruLastName) .OrderByDescending(p => p.PersonID) .First(); if (person != null) { newCI.PersonID = person.PersonID; OfficeAssignment newOA = new OfficeAssignment(); newOA.InstructorID = person.PersonID; db.CourseInstructor.Add(newCI); db.OfficeAssignment.Add(newOA); } db.SaveChanges(); Success(); }
public async Task <IActionResult> PutCourseInstructor(int id, CourseInstructor courseInstructor) { if (id != courseInstructor.CourseId) { return(BadRequest()); } _context.Entry(courseInstructor).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseInstructorExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult Update(long id, CourseInstructor request) { RequiredFields model = new RequiredFields(); model.Instructor = request; object validateFields = _validationService.ValidateRequest("Instructor", model); if (JsonConvert.SerializeObject(validateFields).Length > 2) { return(BadRequest(validateFields)); } try { var response = _instructorRepository.Update(id, request); if (response == 0) { return(NotFound(_NotFound)); } else if (response == 1) { return(BadRequest(new GenericResult { Response = false, Message = "Request cannot be process. Instructor already assigned to user group" })); } else { return(Ok(new GenericResult { Response = true, Message = "Instructor has been updated successfully" })); } } catch (Exception e) { return(BadRequest(e)); } }
//post the checkbox value private void UpdateInstructorCoures(string[] selectedCourses, Instructor instructor) { if (selectedCourses == null) { instructor.CourseInstructors = new List <CourseInstructor>(); return; } var courses = _context.Courses; var selectedcourseHs = new HashSet <string>(selectedCourses); var instructorCourses = new HashSet <int>(instructor.CourseInstructors.Select(c => c.Course.CourseID)); foreach (var course in courses) { if (selectedcourseHs.Contains(course.CourseID.ToString())) { if (!instructorCourses.Contains(course.CourseID)) { instructor.CourseInstructors.Add(new CourseInstructor { CourseID = course.CourseID, InstructorId = instructor.ID }); } } else { if (instructorCourses.Contains(course.CourseID)) { CourseInstructor courseInstructor = instructor.CourseInstructors.FirstOrDefault(i => i.CourseID == course.CourseID); _context.Remove(courseInstructor); } } } }
public async Task <ActionResult <CourseInstructor> > PostCourseInstructor(CourseInstructor courseInstructor) { _context.CourseInstructors.Add(courseInstructor); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCourseInstructor", new { id = courseInstructor.ID }, courseInstructor)); }
public async Task <IActionResult> Edit(int id, [Bind("CourseID,InstructorId")] CourseInstructor courseInstructor) { if (id != courseInstructor.CourseID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(courseInstructor); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseInstructorExists(courseInstructor.CourseID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CourseID"] = new SelectList(_context.Courses, "CourseID", "CourseID", courseInstructor.CourseID); ViewData["InstructorId"] = new SelectList(_context.Instructors, "ID", "FirstNmae", courseInstructor.InstructorId); return(View(courseInstructor)); }
public ActionResult Store(CourseInstructor request) { RequiredFields model = new RequiredFields(); model.Instructor = request; object validateFields = _validationService.ValidateRequest("Instructor", model); if (JsonConvert.SerializeObject(validateFields).Length > 2) { return(BadRequest(validateFields)); } try { var response = _instructorRepository.Add(request); if (response == true) { return(Ok(new GenericResult { Response = response, Message = "Instructor has been successfully saved." })); } else { return(BadRequest(new GenericResult { Response = response, Message = "Instructor is already assigned in user group." })); } } catch (Exception e) { return(BadRequest(e)); } }
//Change Course a Instructor is teaching private static void Q9() { listData.ListInstructor(); string menu1 = "Please input the ID of the INSTRUCTOR you want to update."; int instuctorID = Int32.Parse(AskInput(menu1)); listData.ListCourse(); string courseID = AskInput("Please choose the Course ID you want to change to."); string menu2 = "Are you sure you need to update?\n1.YES\n0.No"; byte answer = byte.Parse(AskInput(menu2)); if (answer == 1) { var query = db.CourseInstructor.FirstOrDefault(i => i.PersonID == instuctorID); if (query != null) { db.CourseInstructor.Remove(query); db.SaveChanges(); CourseInstructor newOne = new CourseInstructor(); newOne.CourseID = short.Parse(courseID); newOne.PersonID = instuctorID; db.CourseInstructor.Add(newOne); db.SaveChanges(); Success(); } } else { ResponseToMenu(); } }
public IActionResult PutCourseInstructor(int id, CourseInstructor model) { var c = db.CourseInstructor.Find(id); c.InjectFrom(model); db.SaveChanges(); return(NoContent()); }
public ActionResult DeleteConfirmed(int id) { CourseInstructor courseInstructor = db.CourseInstructors.Find(id); db.CourseInstructors.Remove(courseInstructor); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Create a new CourseInstructor object. /// </summary> /// <param name="courseID">Initial value of CourseID.</param> /// <param name="personID">Initial value of PersonID.</param> public static CourseInstructor CreateCourseInstructor(int courseID, int personID) { CourseInstructor courseInstructor = new CourseInstructor(); courseInstructor.CourseID = courseID; courseInstructor.PersonID = personID; return(courseInstructor); }
public IActionResult PutCourseInstructor(int id, CourseInstructor model) { var updateItem = db.CourseInstructors.Find(id); updateItem.Instructor = model.Instructor; db.CourseInstructors.Update(updateItem); db.SaveChanges(); return(NoContent()); }
public void PutCourseInstructor(int id, CourseInstructor value) { var courseInstructor = db.CourseInstructor.Find(id); if (courseInstructor != null) { db.CourseInstructor.Update(courseInstructor); db.SaveChanges(); } }
public ActionResult <CourseInstructor> PostCourseInstructor(CourseInstructor model) { if (model != null) { this.db.CourseInstructor.Add(model); this.db.SaveChanges(); return(Ok(model)); } return(null); }
public ActionResult AssignCourse(string Id, InstructorModels.AssignCourse model) { CourseInstructor assignment = new CourseInstructor(); assignment.Course = db.Courses.Single(c => c.Id == model.CourseId); assignment.AspNetUser = db.AspNetUsers.Single(c => c.Id == Id); db.CourseInstructors.Add(assignment); db.SaveChanges(); return(RedirectToAction("ManageInstructors")); }
public async Task <Unit> Handle(Update request, CancellationToken cancellationToken) { var course = await context.Courses.FindAsync(request.CourseId); if (course == null) { throw new BusinessException(HttpStatusCode.NotFound, new { curso = "No se encontró el curso" }); } //throw new Exception("Dicho curso no existe"); course.Title = request.Title ?? course.Title; course.Description = request.Description ?? course.Description; course.Uploaded = request.Uploaded ?? course.Uploaded; course.Created = DateTime.UtcNow; var pricen = context.Prices.Where(x => x.CourseId == course.CourseId).FirstOrDefault(); if (pricen != null) { pricen.Promo = request.Discount ?? pricen.Promo; pricen.ActualPrice = request.PriceActual ?? pricen.ActualPrice; } else { pricen = new Price { PriceId = Guid.NewGuid(), ActualPrice = request.PriceActual ?? 0, Promo = request.Discount ?? 0, CourseId = course.CourseId }; } if (request.Instructors != null && request.Instructors.Count > 0) { var instructorsDB = context.CourseInstructors.Where(x => x.CourseId == request.CourseId).ToList(); foreach (var ins in instructorsDB) { context.CourseInstructors.Remove(ins); } foreach (var ins in request.Instructors) { var newins = new CourseInstructor { CourseId = request.CourseId, InstructorId = ins }; context.CourseInstructors.Add(newins); } } var res = await context.SaveChangesAsync(); return((res > 0) ? Unit.Value : throw new Exception("No se guardaron los cambios")); }
public virtual ActionResult PostEntity(CreateOrUpdateCourseInstructorModel model) { CourseInstructor addEntity = new CourseInstructor(); addEntity.InjectFrom(model); _db.Add(addEntity); _db.SaveChanges(); return(Created("api/CourseInstructor", addEntity)); }
public IActionResult PutCourseInstructor(int id, CourseInstructor model) { var course = this.db.CourseInstructor.Find(id); if (course == null) { return(NotFound()); } course.InjectFrom(model);//使用ValueInjecter範例 this.db.SaveChanges(); return(NoContent()); }
public async Task <Unit> Handle(Execute request, CancellationToken cancellationToken) { Guid _courseId = Guid.NewGuid(); if (request.CourseId != null) { _courseId = request.CourseId ?? Guid.NewGuid(); } var course = new Course { CourseId = _courseId, Title = request.Title, Description = request.Description, DateOfPublication = request.DateOfPublication, CreationDate = DateTime.UtcNow }; await _context.Course.AddAsync(course); if (request.ListInstructor != null) { foreach (var id in request.ListInstructor) { var cursoInstructor = new CourseInstructor { CourseId = _courseId, InstructorId = id }; await _context.CourseInstructor.AddAsync(cursoInstructor); } } /*Add logic insert price course*/ var priceEntity = new Price { CourseId = _courseId, ActualPrice = request.Price, Promotion = request.Promotion, PriceId = Guid.NewGuid() }; await _context.Price.AddAsync(priceEntity); var value = await _context.SaveChangesAsync(); if (value > 0) { return(Unit.Value); } throw new Exception("Someting wrong, dont insert course"); }
public ActionResult Edit([Bind(Include = "Id,CourseId,PersonId")] CourseInstructor courseInstructor) { if (ModelState.IsValid) { db.Entry(courseInstructor).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "CourseName", courseInstructor.CourseId); ViewBag.PersonId = new SelectList(db.Instructors, "PersonId", "LastName", courseInstructor.PersonId); return(View(courseInstructor)); }
public async Task <IActionResult> Create([Bind("CourseID,InstructorId")] CourseInstructor courseInstructor) { if (ModelState.IsValid) { _context.Add(courseInstructor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CourseID"] = new SelectList(_context.Courses, "CourseID", "CourseID", courseInstructor.CourseID); ViewData["InstructorId"] = new SelectList(_context.Instructors, "ID", "FirstNmae", courseInstructor.InstructorId); return(View(courseInstructor)); }
public static CourseInstructor CreateCourseInstructor(string dataAreaId, string personId, global::Microsoft.Dynamics.DataEntities.Person person) { CourseInstructor courseInstructor = new CourseInstructor(); courseInstructor.dataAreaId = dataAreaId; courseInstructor.PersonId = personId; if ((person == null)) { throw new global::System.ArgumentNullException("person"); } courseInstructor.Person = person; return(courseInstructor); }
public IActionResult PutCourseInstructor(int id, CourseInstructor model) { var record = db.CourseInstructor.Find(id); if (record == null) { return(NotFound()); } record.CourseId = model.CourseId; record.InstructorId = model.InstructorId; db.SaveChanges(); return(Ok(model)); }
public ActionResult Edit([Bind(Include = "CourseInstructorID,CourseID,IntructorsID,CourseAssignDate")] CourseInstructor courseInstructor) { if (ModelState.IsValid) { db.Entry(courseInstructor).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CourseID = new SelectList(db.Courses, "CourseID", "Title", courseInstructor.CourseID); ViewBag.InstructorID = new SelectList(db.Instructors, "InstructorID", "LastName", courseInstructor.InstructorID); return(View(courseInstructor)); }
public void PutCoureseInstructor(int cid, int iid, CourseInstructor value) { // var courseInstructor = db.CourseInstructor.Find(id); // courseInstructor.Course = value.Course; // courseInstructor.CourseId = value.CourseId; // courseInstructor.Instructor = value.Instructor; // courseInstructor.InstructorId = value.InstructorId; // var courseInstructor = db.CourseInstructor.Find(cid,iid); // courseInstructor.CourseId=value.CourseId; // courseInstructor.InstructorId=value.InstructorId; // db.CourseInstructor.Update(courseInstructor); db.SaveChanges(); }
// GET: CourseInstructors/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CourseInstructor courseInstructor = db.CourseInstructors.Find(id); if (courseInstructor == null) { return(HttpNotFound()); } return(View(courseInstructor)); }
// GET: CourseInstructors/Details/5 public ActionResult Details(int?id) { if (id == null) { throw new HttpException(404, "Bad request"); } CourseInstructor courseInstructor = db.CourseInstructors.Find(id); if (courseInstructor == null) { return(HttpNotFound()); } return(View(courseInstructor)); }
public bool Add(CourseInstructor request) { var output = false; var validate = _context.CourseInstructor.Where(x => x.userId == request.userId && x.courseId == request.courseId).FirstOrDefault(); if (validate == null) { request.createdAt = DateTime.Now; request.updatedAt = DateTime.Now; var model = _context.CourseInstructor.Add(request); Save(); output = true; } return(output); }
public ActionResult Create(CourseInstructor newinstructor) { if (ModelState.IsValid) { var db = new SchoolEntities(); db.CourseInstructors.Add(newinstructor); db.SaveChanges(); return(RedirectToAction("Instructors")); } else { return(View(newinstructor)); } }
/// <summary> /// There are no comments for CourseInstructors in the schema. /// </summary> public void AddToCourseInstructors(CourseInstructor courseInstructor) { base.AddObject("CourseInstructors", courseInstructor); }
/// <summary> /// Create a new CourseInstructor object. /// </summary> /// <param name="courseID">Initial value of CourseID.</param> /// <param name="personID">Initial value of PersonID.</param> public static CourseInstructor CreateCourseInstructor(int courseID, int personID) { CourseInstructor courseInstructor = new CourseInstructor(); courseInstructor.CourseID = courseID; courseInstructor.PersonID = personID; return courseInstructor; }