//Add Student public ActionResult AddStudent() { if (Session["AdminLgnFlag"] != null) { var tmp = (Admin)Session["AdminLgnFlag"]; ViewData["admin"] = tmp; ParentStudentModel model = new ParentStudentModel(); model.ClassList = db.Classes.ToList <Class>(); return(View(model)); } return(RedirectToAction("Index")); }
public ActionResult DeleteStudent(ParentStudentModel model) { if (Session["AdminLgnFlag"] != null) { var temp = (Admin)Session["AdminLgnFlag"]; ViewData["admin"] = temp; Student std = db.Students.Find(model.Student.Id); db.Students.Remove(std); db.SaveChanges(); return(RedirectToAction("GetStudent")); } return(RedirectToAction("Index")); }
public ActionResult EditStudent(ParentStudentModel model) { if (Session["AdminLgnFlag"] != null) { var temp = (Admin)Session["AdminLgnFlag"]; ViewData["admin"] = temp; Student std = new Student(); std = model.Student; db.Entry(std).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("GetStudent")); } return(RedirectToAction("Index")); }
//DeleteStudent public ActionResult DeleteStudent(int id) { if (Session["AdminLgnFlag"] != null) { var temp = (Admin)Session["AdminLgnFlag"]; ViewData["admin"] = temp; ParentStudentModel model = new ParentStudentModel(); Student std = new Student(); std = db.Students.Find(id); model.Class = db.Classes.Find(std.Class_Id); model.Student = std; return(View(model)); } return(RedirectToAction("Index")); }
public ActionResult AddStudent(ParentStudentModel parentStudentModel) { if (Session["AdminLgnFlag"] != null) { Student student = new Student(); student.Std_Name = parentStudentModel.Student.Std_Name; student.Father_Name = parentStudentModel.Student.Father_Name; student.Age = parentStudentModel.Student.Age; student.Address = parentStudentModel.Student.Address; student.Contact_Number = parentStudentModel.Student.Contact_Number; student.Email = parentStudentModel.Student.Email; student.Class_Id = parentStudentModel.Student.Class_Id; int temp = db.Students.Count <Student>(); student.Reg_No = GetRegno(temp); student.Password = RandomString(); db.Students.Add(student); db.SaveChanges(); //smtp #region smtp var senderEmail = new MailAddress("*****@*****.**", "Danish"); var receiverEmail = new MailAddress(student.Email, student.Std_Name); var password = "******"; var sub = "Portal Username and Password"; var body = "Regno: " + student.Reg_No + "\nPassword: "******"\n Please Download your chalan from the student portal!"; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(senderEmail.Address, password) }; using (var mess = new MailMessage(senderEmail, receiverEmail) { Subject = sub, Body = body }) { smtp.Send(mess); } #endregion //smtp end //Generate Challan #region Generate Chalan Fee chalan = new Fee(); chalan.Class_Id = student.Class_Id; chalan.Student_Id = student.Id; //geting fee detail from class var Res = db.Classes.Find(chalan.Class_Id); var tfee = Res.Admission_Fee + Res.Tuition_Fee + Res.Exam_Fee; chalan.Total_Fee = tfee; chalan.Generation_Date = System.DateTime.Now.Date; chalan.Due_Date = System.DateTime.Now.AddDays(10).Date; db.Fees.Add(chalan); db.SaveChanges(); #endregion //Generate ChallanEnd var tmp = (Admin)Session["AdminLgnFlag"]; ViewData["admin"] = tmp; ViewData["StudentAdded"] = "Successfully added!"; ParentStudentModel model = new ParentStudentModel(); model.ClassList = db.Classes.ToList <Class>(); return(View(model)); } return(RedirectToAction("Index")); }