public ActionResult SaveAddCourse(Session registerDetails) { //We check if the model state is valid or not. We have used DataAnnotation attributes. //If any form value fails the DataAnnotation validation the model state becomes invalid. if (ModelState.IsValid) { //create database context using Entity framework using (var databaseContext = new Attendance_MarkingEntities()) { //If the model state is valid i.e. the form values passed the validation then we are storing the User's details in DB. Session reglog = new Session(); //Save all details in RegitserUser object reglog.SessionId = registerDetails.SessionId; reglog.SessionDescription = registerDetails.SessionDescription; reglog.Skills = registerDetails.Skills; reglog.SessionDate = registerDetails.SessionDate; reglog.SessionTime = registerDetails.SessionTime; //Calling the SaveDetails method which saves the details. databaseContext.Sessions.Add(reglog); databaseContext.SaveChanges(); } ViewBag.Message = " Session Details Sucessfully Saved"; //return View("Register"); return(View("AddSession")); } else { //If the validation fails, we are returning the model object with errors to the view, which will display the error messages. return(View("AddSession", registerDetails)); } }
//function to check if User is valid or not public UserDetail IsValidUser(UserLoginViewModel model) { using (var dataContext = new Attendance_MarkingEntities()) { //Retireving the user details from DB based on username and password enetered by user. UserDetail user = dataContext.UserDetails.Where(query => query.UserId.Equals(model.UserId) && query.Password.Equals(model.Password)).SingleOrDefault(); //If user is present, then true is returned. if (user == null) { return(null); } //If user is not present false is returned. else { return(user); } } }
public ActionResult SaveRegisterDetails(UserDetail registerDetails) { //We check if the model state is valid or not. We have used DataAnnotation attributes. //If any form value fails the DataAnnotation validation the model state becomes invalid. if (ModelState.IsValid) { //create database context using Entity framework using (var databaseContext = new Attendance_MarkingEntities()) { //If the model state is valid i.e. the form values passed the validation then we are storing the User's details in DB. UserDetail reglog = new UserDetail(); //Save all details in RegitserUser object reglog.FirstName = registerDetails.FirstName; reglog.LastName = registerDetails.LastName; reglog.Age = registerDetails.Age; reglog.Gender = registerDetails.Gender; reglog.ContactNumber = registerDetails.ContactNumber; reglog.UserId = registerDetails.UserId; reglog.Password = registerDetails.Password; //Calling the SaveDetails method which saves the details. databaseContext.UserDetails.Add(reglog); databaseContext.SaveChanges(); } ViewBag.Message = registerDetails.FirstName + " " + registerDetails.LastName + " your Details Sucessfully Saved"; //return View("Register"); return(View("UserRegister")); } else { //If the validation fails, we are returning the model object with errors to the view, which will display the error messages. return(View("UserRegister", registerDetails)); } }