public ActionResult Create([Bind(Include = "Id,DeptName")] Department department) { if (ModelState.IsValid) { db.Departments.Add(department); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(department)); }
public ActionResult Create([Bind(Include = "CrsId,CrsName")] Course course) { if (ModelState.IsValid) { db.Courses.Add(course); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(course)); }
public ActionResult Create(Student std) { if (ModelState.IsValid) { db.Students.Add(std); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(db.Departments.ToList(), "DeptId", "DeptName"); return(View(std)); }
public ActionResult Create([Bind(Include = "Id,Name,Age,Email,Password,Img,DeptId")] Student student, HttpPostedFileBase img) { if (ModelState.IsValid) { if (img != null) { string filename = student.Name + DateTime.Now.Millisecond + "." + img.FileName.Split('.')[1]; img.SaveAs(Server.MapPath("~/Imgs/") + filename); student.Img = filename; } else { student.Img = "/noone.png"; } db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DeptId = new SelectList(db.Departments, "Id", "DeptName", student.DeptId); return(View(student)); }
private async Task UploadFileAsync(Student student, IFormFile file) { var fileExtension = Path.GetExtension(Path.GetFileName(file.FileName)); var newFileName = String.Concat(Convert.ToString(student.Id), fileExtension); string filePath = Path.Combine("wwwroot/images", newFileName); student.image = newFileName; _db.SaveChanges(); using (Stream fileStream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(fileStream); } }
public Course Add(Course elment) { _db.courses.Add(elment); _db.SaveChanges(); return(elment); }
public void Delete(int elment) { _db.students.Remove(Details(elment)); _db.SaveChanges(); }
public Department Add(Department elment) { _db.departments.Add(elment); _db.SaveChanges(); return(elment); }