public ActionResult Edit(Course course) { _db.Entry(course).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Course course, int StudentId) { _db.Courses.Add(course); if (StudentId != 0) { _db.CourseStudent.Add(new CourseStudent() { StudentId = StudentId, CourseId = course.CourseId }); } _db.SaveChanges(); return RedirectToAction("Index"); }
public ActionResult Create(Student student, int CourseId) { _db.Students.Add(student); if (CourseId != 0) { _db.CourseStudent.Add(new CourseStudent() { CourseId = CourseId, StudentId = student.StudentId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Course course, int DepartmentId) { _db.Courses.Add(course); if (DepartmentId != 0) { _db.DepartmentCourseStudent.Add(new DepartmentCourseStudent() { DepartmentId = DepartmentId, CourseId = course.CourseId }); } _db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Create(RegistrarCreateViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; // If the Photo property on the incoming model object is not null, then the user // has selected an image to upload. if (model.Photo != null) { // The image must be uploaded to the images folder in wwwroot // To get the path of the wwwroot folder we are using the inject // HostingEnvironment service provided by ASP.NET Core string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images"); Console.WriteLine(uploadsFolder); // To make sure the file name is unique we are appending a new // GUID value and and an underscore to the file name uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); Console.WriteLine(filePath); // Use CopyTo() method provided by IFormFile interface to // copy the file to wwwroot/images folder model.Photo.CopyTo(new FileStream(filePath, FileMode.Create)); } Course newCourse = new Course { Name = model.Name, // Store the file name in PhotoPath property of the Course object // which gets saved to the Courses database table Image = uniqueFileName }; _db.Courses.Add(newCourse); _db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(Department department) { _db.Departments.Add(department); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Course course) { _db.Courses.Add(course); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Student student) { _db.Students.Add(student); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Professor professor) { _db.Professors.Add(professor); _db.SaveChanges(); return(RedirectToAction("Index")); }