示例#1
0
        public ActionResult Create([Bind(Include = "Id,DeptName")] Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(department));
        }
示例#2
0
        public ActionResult Create([Bind(Include = "CrsId,CrsName")] Course course)
        {
            if (ModelState.IsValid)
            {
                db.Courses.Add(course);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(course));
        }
示例#3
0
        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));
        }
示例#4
0
        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));
        }
示例#5
0
        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);
            }
        }
示例#6
0
 public Course Add(Course elment)
 {
     _db.courses.Add(elment);
     _db.SaveChanges();
     return(elment);
 }
示例#7
0
 public void Delete(int elment)
 {
     _db.students.Remove(Details(elment));
     _db.SaveChanges();
 }
示例#8
0
 public Department Add(Department elment)
 {
     _db.departments.Add(elment);
     _db.SaveChanges();
     return(elment);
 }