public ActionResult Create([Bind(Include = "StudID,StudCode,FullName,MajorID,MinorID,Year,BirthDate,Tel,Email,Remark")] tblStudent tblStudent) { if (ModelState.IsValid) { if (db.tblStudents.Where(h => h.StudCode == tblStudent.StudCode).ToList().Count > 0) { TempData["alertMessage"] = "รหัสนักศึกษาไม่สามารถซ้ำได้"; ViewBag.MinorID = new SelectList(db.tblMinors, "MinorID", "MinorName", tblStudent.MinorID); return(View(tblStudent)); } else { tblStudent.StudID = Guid.NewGuid().ToString(); db.tblStudents.Add(tblStudent); //Save User tblUser TempUser = new tblUser(); TempUser.UserID = Guid.NewGuid().ToString(); TempUser.UserName = tblStudent.StudCode; TempUser.Password = tblStudent.BirthDate.ToString("ddMMyyyy"); TempUser.relateID = tblStudent.StudID; TempUser.relateTable = "tblStudent"; db.tblUsers.Add(TempUser); db.SaveChanges(); return(RedirectToAction("Index")); } } ViewBag.MinorID = new SelectList(db.tblMinors, "MinorID", "MinorName", tblStudent.MinorID); return(View(tblStudent)); }
public ActionResult Create([Bind(Include = "teachID,teachCode,FullName,Education,Position,Expert,MajorID,BirthDate,Tel,Email,Remark")] tblTeacher tblTeacher) { if (ModelState.IsValid) { if (db.tblTeachers.Where(h => h.teachCode == tblTeacher.teachCode).ToList().Count > 0) { TempData["alertMessage"] = "รหัสอาจารย์ไม่สามารถซ้ำได้"; ViewBag.MajorID = new SelectList(db.tblMajors, "MajorID", "MajorName", tblTeacher.MajorID); return(View(tblTeacher)); } else { tblTeacher.teachID = Guid.NewGuid().ToString(); db.tblTeachers.Add(tblTeacher); //Save User tblUser TempUser = new tblUser(); TempUser.UserID = Guid.NewGuid().ToString(); TempUser.UserName = tblTeacher.Email; TempUser.Password = tblTeacher.BirthDate.ToString("ddMMyyyy"); TempUser.relateID = tblTeacher.teachID; TempUser.relateTable = "tblTeacher"; db.tblUsers.Add(TempUser); db.SaveChanges(); return(RedirectToAction("Index")); } } ViewBag.MajorID = new SelectList(db.tblMajors, "MajorID", "MajorName", tblTeacher.MajorID); return(View(tblTeacher)); }
public JsonResult Create(tblCourseHD CourseHD) { try { var errors = ModelState .Where(x => x.Value.Errors.Count > 0) .Select(x => new { x.Key, x.Value.Errors }) .ToArray(); if (ModelState.IsValid) { // If sales main has SalesID then we can understand we have existing sales Information // So we need to Perform Update Operation string TempID = Guid.NewGuid().ToString(); CourseHD.CourseHDID = TempID; if (CourseHD.TimeStart_txt.Contains(":")) { string[] TempTimeStart = CourseHD.TimeStart_txt.Split(':'); CourseHD.TimeStart = (Convert.ToInt32(TempTimeStart[0]) * 60) + Convert.ToInt32(TempTimeStart[0]); } else { CourseHD.TimeStart = 0; } if (CourseHD.TimeEnd_txt.Contains(":")) { string[] TempTimeEnd = CourseHD.TimeEnd_txt.Split(':'); CourseHD.TimeEnd = (Convert.ToInt32(TempTimeEnd[0]) * 60) + Convert.ToInt32(TempTimeEnd[0]); } else { CourseHD.TimeEnd = 0; } foreach (tblCourseDT DT in CourseHD.tblCourseDTs) { DT.CourseHDID = TempID; DT.CourseDTID = Guid.NewGuid().ToString(); } db.tblCourseHDs.Add(CourseHD); db.SaveChanges(); // If Sucess== 1 then Save/Update Successfull else there it has Exception return(Json(new { Success = 1 })); } } catch (Exception ex) { // If Sucess== 0 then Unable to perform Save/Update Operation and send Exception to View as JSON return(Json(new { Success = 0 })); } return(Json(new { Success = 0 })); }
public ActionResult Create([Bind(Include = "MajorID,MajorCode,MajorName,MajorDetail")] tblMajor tblMajor) { if (ModelState.IsValid) { tblMajor.MajorID = Guid.NewGuid().ToString(); db.tblMajors.Add(tblMajor); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblMajor)); }
public ActionResult Create([Bind(Include = "SujectID,SujectCode,SujectName,SujectDetail")] tblSuject tblSuject) { if (ModelState.IsValid) { tblSuject.SujectID = Guid.NewGuid().ToString(); db.tblSujects.Add(tblSuject); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblSuject)); }
public ActionResult Create([Bind(Include = "UserID,UserName,Password,relateID,relateTable,Remark")] tblUser tblUser) { if (ModelState.IsValid) { tblUser.UserID = Guid.NewGuid().ToString(); tblUser.relateID = tblUser.UserID; tblUser.relateTable = "admin"; db.tblUsers.Add(tblUser); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblUser)); }