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

                    //Save all details in RegitserUser object

                    reglog.First_Name = registerDetails.FirstName;
                    reglog.Last_Name  = registerDetails.LastName;
                    reglog.Email      = registerDetails.Email;
                    reglog.Password   = registerDetails.Pin;
                    reglog.Followers  = 0;
                    reglog.Following  = 0;

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

                ViewBag.Message = "User Details Saved";
                return(View("Login"));
            }
            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));
            }
        }
Ejemplo n.º 2
0
 //function to check if User is valid or not
 public User IsValidUser(LoginViewModel model)
 {
     using (var dataContext = new CorkBoardTemplateEntities())
     {
         //Retireving the user details from DB based on username and password enetered by user.
         User user = dataContext.Users.Where(query => query.Email.Equals(model.Email) && query.Password.Equals(model.Pin)).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);
         }
     }
 }