Ejemplo n.º 1
0
        public IActionResult Index1(SignUp obj)
        {
            DatabaseConnector db = new DatabaseConnector();

            if (ModelState.IsValid)
            {
                if (db.isUsernameValid(obj.username))
                {
                    if (db.checkEmail(obj.email))
                    {
                        if (obj.password.Length >= 8)
                        {
                            if (obj.password == obj.retypePassword)
                            {
                                if (db.isUsernameExist(obj.username, -1, false))
                                {
                                    ModelState.AddModelError("username", "This username is already taken..!");
                                    return(View());
                                }
                                else
                                {
                                    if (db.isEmailExist(obj.email, -1, false))
                                    {
                                        ModelState.AddModelError("email", "Already Account Exists on this Email..!");
                                        return(View());
                                    }
                                    else
                                    {
                                        User user = new User();
                                        user.username = obj.username;
                                        user.password = obj.password;
                                        user.email    = obj.email;
                                        if (obj.myImage != null)
                                        {
                                            string filename  = Path.GetFileName(obj.myImage.FileName);
                                            string extension = Path.GetExtension(obj.myImage.FileName);
                                            string filepath  = Path.Combine("C:/Users/Abid Shafique/Desktop/Assignment no 3/Assignment no 3/wwwroot/ProfileImages/", user.username + extension);
                                            using (FileStream stream = new FileStream(filepath, FileMode.Create))
                                            {
                                                obj.myImage.CopyTo(stream);
                                            }
                                            user.imageName = filename;
                                        }
                                        db.AddUserInDBMS(user);
                                        return(View("SuccessStatus"));
                                    }
                                }
                            }
                            else
                            {
                                ModelState.AddModelError("retypePassword", "Retype Password doesn't match with Password..!");
                                return(View());
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("password", "Password must be of at least 8 Characters..!");
                            return(View());
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("email", "Entered Email is not in Correct Format");
                        return(View());
                    }
                }
                else
                {
                    ModelState.AddModelError("username", "Enter Usename without Space");
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }