コード例 #1
0
        /// <summary>
        /// Validates if all fields are entered
        /// </summary>
        /// <param name="newuser">User what will be adding</param>
        /// <returns></returns>
        private bool Validation(UserAccont newuser)
        {
            if (newuser.Person.FirstName != null && newuser.Person.LastName != null && newuser.Person.EMailAddress != null && Password != null)
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
 //constructor
 public RegistrationVM()
 {
     _accontRepository = new UserAccontRepository(new TrackPlaceDbContext());
     RegisterCommand   = new RelayCommand(ExecuteMethodRegister);
     _userAccont       = new UserAccont()
     {
         Password = new Password(),
         Person   = new Person()
     };
 }
コード例 #3
0
 public LoginVM()
 {
     _userAccontRepository = new UserAccontRepository(new TrackPlaceDbContext());
     _user = new UserAccont()
     {
         Password = new Password(),
         Person   = new Person()
     };
     RegisterCommand = new RelayCommand(ExecuteRegister);
     LoginCommand    = new RelayCommand(ExecuteLogin);
 }
コード例 #4
0
 public ActionResult Register(UserAccont account)
 {
     if (ModelState.IsValid)
     {
         using (OurDbContext db = new OurDbContext())
         {
             db.userAccount.Add(account);
             db.SaveChanges();
         }
         ModelState.Clear();
         ViewBag.Message = account.FirstName + " " + account.LastName + " succesfully registered.";
     }
     return(View());
 }
コード例 #5
0
 public ActionResult Login(UserAccont user)
 {
     using (OurDbContext db = new OurDbContext())
     {
         var usr = db.userAccount.Single(u => u.Login == user.Login && u.Password == user.Password);
         if (usr != null)
         {
             Session["UserID"] = usr.UserID.ToString();
             Session["Login"]  = usr.Login.ToString();
             return(RedirectToAction("LoggenIn"));
         }
         else
         {
             ModelState.AddModelError("", "Username or Password is wrong.");
         }
     }
     return(View());
 }
コード例 #6
0
        /// <summary>
        /// Command for registering user
        /// </summary>
        /// <param name="obj">take sin view object</param>
        private void ExecuteMethodRegister(object obj)
        {
            UserAccont newUser = new UserAccont()
            {
                Password = new Password()
                {
                    PasswordName = UserAccont.Password.PasswordName
                },
                Person = new Person()
                {
                    FirstName    = UserAccont.Person.FirstName,
                    LastName     = UserAccont.Person.LastName,
                    EMailAddress = UserAccont.Person.EMailAddress
                }
            };

            if (Password != _userAccont.Password.PasswordName)
            {
                ErrorText = "Salsõnad ei ühti";
                return;
            }

            else if (_accontRepository.IfExsists(newUser))
            {
                ErrorText = "Selline kasutaja juba on olemas andmebaasis";
                return;
            }
            else if (!Validation(newUser))
            {
                ErrorText = "kõik väljad peavad olema täidetud!";
                return;
            }

            Logger.Logger.log($"Kasutaja loodudˇ{DateTime.Now}", $"{newUser.Person.FirstName}_{newUser.Person.LastName}_log_file");
            _accontRepository.Add(newUser);
            _accontRepository.SaveChanges();
            MessageBox.Show("Olete registeeritud!");
            Window win = obj as Window;

            win.Close();
        }