public ActionResult Register([Bind(Include = "Id,Name,Email,ContactNo,Date,Address,DepartmentId")] Student student) { if (ModelState.IsValid) { student.StudentRegNo = GetStudentRegNo(student); db.Students.Add(student); db.SaveChanges(); WebMail.SmtpServer = "smtp-mail.outlook.com"; WebMail.SmtpPort = 587; WebMail.SmtpUseDefaultCredentials = true; WebMail.EnableSsl = true; WebMail.UserName = "******"; WebMail.Password = "******"; WebMail.From = "*****@*****.**"; WebMail.Send(to: student.Email, subject: "Studentship Confirmation", body: "Hello " + " " + student.Name + " " + "<br />" + "Your Matriculation Number is :" + " " + student.StudentRegNo + "<br /> " + "Your Registration was Successful " + "<br />", isBodyHtml: true); ViewBag.Message = "Student Registered Successfully"; } ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "DeptCode", student.DepartmentId); return(View(student)); }
public ActionResult Create([Bind(Include = "Id,RegisterStudentId,Name,Email,DepartmentId,CourseId,GradeLetterId")] StudentResult studentResult) { if (ModelState.IsValid) { var enrollCourses = db.StudentResults.Where(m => m.RegisterStudentId == studentResult.RegisterStudentId && m.CourseId == studentResult.CourseId).ToList(); if (enrollCourses.Count() == 1) { var id = enrollCourses[0].Id; // var date = enrollCourses[0].EnrollDate; studentResult.Id = id; // studentResult.EnrollDate = date; db.StudentResults.AddOrUpdate(studentResult); db.SaveChanges(); ViewBag.Msg = "Update Result Successful!"; } else { db.StudentResults.Add(studentResult); db.SaveChanges(); ViewBag.Msg = "Result Saved Successful!"; } //db.StudentResults.Add(studentResult); // int aa = db.SaveChanges(); // return RedirectToAction("Create"); } ViewBag.CourseId = new SelectList(db.Courses, "Id", "Code", studentResult.CourseId); ViewBag.GradeLetterId = new SelectList(db.GradeLetters, "Id", "Grade", studentResult.GradeLetterId); ViewBag.RegisterStudentId = new SelectList(db.RegisterStudents, "Id", "RegNo", studentResult.RegisterStudentId); return(View(studentResult)); }
public T Add(T itemToAdd) { var entity = dbContext.Add <T>(itemToAdd); dbContext.SaveChanges(); return(entity.Entity); }
public Task <bool> Add(User newUserModel) { var currentDate = DateTime.UtcNow; try { //create salt and password hash var randomPass = EncryptionService.GenerateRandomPassword(8); var salt = EncryptionService.CreateRandomSalt(); var passwordHash = EncryptionService.HashPassword(randomPass, salt); newUserModel.PasswordHash = passwordHash; newUserModel.PasswordSalt = salt; newUserModel.CreatedDateUtc = currentDate; db.User.Add(newUserModel); db.SaveChanges(); return(Task.Run(() => true)); } catch { return(Task.Run(() => false)); } }
public ActionResult Create(ResultEntry resultentry) { if (ModelState.IsValid) { var result = db.ResultEntries.Count( r => r.StudentId == resultentry.StudentId && r.CourseId == resultentry.CourseId) == 0; if (result) { Grade aGrade = db.Grades.Where(g => g.GradeId == resultentry.GradeId).FirstOrDefault(); EnrollCourse resultEnrollCourse = db.EnrollCourses.FirstOrDefault(r => r.CourseId == resultentry.CourseId && r.StudentId == resultentry.StudentId); if (resultEnrollCourse != null) { resultEnrollCourse.GradeName = aGrade.Name; } db.ResultEntries.Add(resultentry); db.SaveChanges(); TempData["success"] = "Result Successfully Entered"; return(RedirectToAction("Create")); } else { TempData["Already"] = "Result Of This Course has Already Been Assigned"; return(RedirectToAction("Create")); } } ViewBag.StudentId = new SelectList(db.Students, "StudentId", "RegistrationId", resultentry.StudentId); ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "Code", resultentry.CourseId); ViewBag.GradeId = new SelectList(db.Grades, "GradeId", "Name", resultentry.GradeId); return(View(resultentry)); }
public int Save(StudentDto dto) { // query var s = Mapper.Map <StudentDto, Student>(dto); s.CreateBy = "admin"; s.CreateDate = DateTime.Now; //var student = new Student() //{ // Name = dto.Name, // Roll = dto.Roll, // Reg = dto.Reg, // CreateBy = "Admin", // CreateDate = DateTime.Now //}; _dbContext.Students.Add(s); //command _dbContext.SaveChanges(); //result return(s.Id); }
public ActionResult Create([Bind(Include = "Id,DepartmentId,TeacherId,CreditToBeTaken,RemainingCredit,CourseId,Name,Credit")] AssignToTeacher assignToTeacher) { if (ModelState.IsValid) { db.AssignToTeachers.Add(assignToTeacher); db.SaveChanges(); // return RedirectToAction("Create"); if (assignToTeacher.CourseId != 0) { var coursess = db.Courses.FirstOrDefault(x => x.Id == assignToTeacher.CourseId); coursess.TeacherId = assignToTeacher.TeacherId; coursess.CourseStatus = true; db.Courses.AddOrUpdate(coursess); db.SaveChanges(); } } ViewBag.CourseId = new SelectList(db.Courses, "Id", "Code", assignToTeacher.CourseId); ViewBag.DepartmentId = new SelectList(db.Departments, "Id", "Code", assignToTeacher.DepartmentId); ViewBag.TeacherId = new SelectList(db.Teachers, "Id", "Name", assignToTeacher.TeacherId); return(View(assignToTeacher)); }
public ActionResult Create([Bind(Include = "TeacherCourseAssignId,DepartmentId,TeacherId,CourseId")] TeacherCourseAssign teachercourseassign) { if (ModelState.IsValid) { var creditTaken = db.Teachers.Where(t => t.TeacherId == teachercourseassign.TeacherId).Select(t => t.Credit).DefaultIfEmpty(0).Sum(); var assignedCredit = db.TeacherCourseAssigns.Where(t => t.TeacherId == teachercourseassign.TeacherId).Include(c => c.Course).Where(c => c.CourseId == c.Course.CourseId).Select(c => c.Course.Credit).DefaultIfEmpty(0).Sum(); var selectedCourse = db.Courses.FirstOrDefault(x => x.CourseId == teachercourseassign.CourseId); var selectedSubjectCreditt = selectedCourse.Credit; var remainingCredit = creditTaken - assignedCredit; if (selectedSubjectCreditt > remainingCredit) { UpdateTeacherCredit(creditTaken + (selectedSubjectCreditt - remainingCredit), teachercourseassign.TeacherId); } UpdateCourseStatus(1, teachercourseassign.CourseId); db.TeacherCourseAssigns.Add(teachercourseassign); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "Code", teachercourseassign.CourseId); ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Code", teachercourseassign.DepartmentId); ViewBag.TeacherId = new SelectList(db.Teachers, "TeacherId", "Name", teachercourseassign.TeacherId); return(View(teachercourseassign)); }
public void AddStudents(List <Student> students) { foreach (Student s in students) { context.Add <Student>(s); } context.SaveChanges(); }
public ActionResult Create(Batch model) { if (ModelState.IsValid) { db.Batchs.Add(model); db.SaveChanges(); } return(RedirectToAction("BatchList", "Batch")); }
public ActionResult Create(Department model) { if (ModelState.IsValid) { db.Departments.Add(model); db.SaveChanges(); } return(RedirectToAction("DepartmentList", "Department")); }
public ActionResult Edit([Bind(Include = "Id,Name,Email,ContactNo,Date,Address,DepartentId,StudentRegNo")] Student student) { if (ModelState.IsValid) { db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Edit([Bind(Include = "Id,FirstName")] Name name) { if (ModelState.IsValid) { db.Entry(name).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(name)); }
public ActionResult Edit([Bind(Include = "Id,DeptCode,DeptName")] Department department) { if (ModelState.IsValid) { db.Entry(department).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(department)); }
public ActionResult Create([Bind(Include = "Id,Name,Image,Birthday,PhoneNumber,Email,Password,Status")] Teacher teacher) { if (ModelState.IsValid) { db.Teachers.Add(teacher); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(teacher)); }
public ActionResult Create(Designation designation) { if (ModelState.IsValid) { db.Designations.Add(designation); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(designation)); }
public ActionResult Create(ClassRoom classroom) { if (ModelState.IsValid) { db.ClassRooms.Add(classroom); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(classroom)); }
public ActionResult Create([Bind(Include = "Id_TipoLab,Tipo_Lab")] TipoLab tipoLab) { if (ModelState.IsValid) { db.TipoLab.Add(tipoLab); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tipoLab)); }
public ActionResult Create(WeekDay weekday) { if (ModelState.IsValid) { db.WeekDays.Add(weekday); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(weekday)); }
public ActionResult Create(Semester semester) { if (ModelState.IsValid) { db.Semesters.Add(semester); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(semester)); }
public ActionResult Create([Bind(Include = "Id_Departamento,Departamento1")] Departamento departamento) { if (ModelState.IsValid) { db.Departamento.Add(departamento); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(departamento)); }
public ActionResult Create([Bind(Include = "Id_Carrera,Carrera1")] Carrera carrera) { if (ModelState.IsValid) { db.Carrera.Add(carrera); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(carrera)); }
public ActionResult Create([Bind(Include = "Id_Dias,Dias1")] Dias dias) { if (ModelState.IsValid) { db.Dias.Add(dias); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dias)); }
public ActionResult Create([Bind(Include = "Id,Name,Image,FatherName,MotherName,Birthday,Gender,ResidentialAddress,PermanentAddress,SportDetails,Email,Password,Status")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Create(ResultGrade resultgrade) { if (ModelState.IsValid) { db.ResultGrades.Add(resultgrade); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(resultgrade)); }
public ActionResult Create([Bind(Include = "Id_Status,Status1")] Status status) { if (ModelState.IsValid) { db.Status.Add(status); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(status)); }
public ActionResult Create([Bind(Include = "DepartmentId,Code,Name")] Department department) { if (ModelState.IsValid) { db.Departments.Add(department); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(department)); }
public ActionResult Create([Bind(Include = "Id_Rol,Rol1")] Rol rol) { if (ModelState.IsValid) { db.Rol.Add(rol); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(rol)); }
public ActionResult Create([Bind(Include = "Id,Name,StudentId")] Department department) { if (ModelState.IsValid) { db.Departments.Add(department); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StudentId = new SelectList(db.Students, "Id", "Name", department.StudentId); return(View(department)); }
public ActionResult Create([Bind(Include = "StudentId,Name,Email,Address,DepartmentId")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Name", student.DepartmentId); return(View(student)); }
public static void Main() { var db = new UniversityDbContext(); //var student = new Student() //{ // FirstName = "Pesho", // LastName = "Peshev", // ForumPoints = 0 //}; //db.Students.Add(student); //db.SaveChanges(); var savedStudent = db.Students.First(); db.Students.Remove(savedStudent); db.SaveChanges(); }