Exemplo n.º 1
0
        public ActionResult SaveRegisterDetails(Register 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 CAFEEntities2())
                {
                    //If the model state is valid i.e. the form values passed the validation then we are storing the User's details in DB.
                    RegisterUser reglog = new RegisterUser();

                    //Save all details in RegitserUser object

                    reglog.FirstName = registerDetails.FirstName;
                    reglog.LastName  = registerDetails.LastName;
                    reglog.Email     = registerDetails.Email;
                    reglog.Password  = registerDetails.Password;

                    //Calling the SaveDetails method which saves the details.
                    databaseContext.RegisterUsers.Add(reglog);
                    databaseContext.SaveChanges();
                }

                ViewBag.Message = "User Details Saved";
                return(View("GaugeChart"));
            }
            else
            {
                //If the validation fails, we are returning the model object with errors to the view, which will display the error messages.
                return(View("Register", registerDetails));
            }
        }
Exemplo n.º 2
0
        public ActionResult Logout()
        {
            int data = Convert.ToInt32(Session["UserID"]);

            using (var datacontext = new CAFEEntities2())
            {
                RegisterUser userDetail = datacontext.RegisterUsers.Where(x => x.Id == data).SingleOrDefault();
                if (userDetail != null)
                {
                    userDetail.IsActive   = false;
                    userDetail.LogoutTime = DateTime.Now;
                    datacontext.SaveChanges();
                }
            }
            FormsAuthentication.SignOut();
            Session.Abandon();     // it will clear the session at the end of request
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
 //function to check if User is valid or not
 public RegisterUser IsValidUser(Login model)
 {
     using (var dataContext = new CAFEEntities2())
     {
         //Retireving the user details from DB based on username and password enetered by user.
         RegisterUser user = dataContext.RegisterUsers.Where(query => query.Email.Equals(model.Email) && query.Password.Equals(model.Password)).SingleOrDefault();
         //If user not present
         if (user == null)
         {
             return(null);
         }
         //If user is present
         else
         {
             user.IsActive = true;
             dataContext.SaveChanges();
             return(user);
         }
     }
 }