Exemplo n.º 1
0
 public ProfileWindow(UserInfo generalInfo, string add1Title, string add1Value, string add2Title=null, string add2Value=null)
 {
     InitializeComponent();
     this.info = generalInfo;
     this.add1Title = add1Title + ":";
     this.add1Value = add1Value;
     this.add2Title = add2Title;
     this.add2Value = add2Value;
     info = generalInfo;
     lblStatus.Text = info.GetType().Name.Replace("Info", string.Empty);
 }
Exemplo n.º 2
0
        //returns new UserID
        public static int AddNewUser(UserInfo u, System.Data.Common.DbTransaction transaction = null)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                if (transaction != null)
                {
                    context.Database.UseTransaction(transaction);
                }
                User newUser = u.GetUser();
                if (!Util.IsValidEmail(u.Email))
                    throw new ArgumentException("Email string is not a valid email!");
                newUser.Password = Crypter.Blowfish.Crypt(newUser.Password); //newUser entity contains uncrypted password!
                context.Users.Add(newUser);
                context.SaveChanges();

                return newUser.UserID;
            }
        }
Exemplo n.º 3
0
        private void GatherInfoFromFields()
        {
            User u = new User();
            u.UserID = int.Parse(lblUserID.Text);
            u.FirstName = lblFirstName.Text;
            u.LastName = txtLastName.Text;
            u.Patronymic = lblPatronymic.Text;
            try
            {
                u.DateOfBirth = DateTime.Parse(lblDob.Text);
            }
            catch
            { u.DateOfBirth = null; }
            u.Password = this.info.Password;

            if (!Util.IsValidEmail(txtEmail.Text))
                throw new ArgumentException("Email string is not a valid email!");
            u.Email = txtEmail.Text;
            u.Phone = txtPhone.Text;
            UserInfo newInfo = new UserInfo(u);
            this.info = newInfo;
        }
Exemplo n.º 4
0
        public static void UpdateUserInfo(UserInfo userInfo)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                User userToUpdate = (User)context.Set<User>().Find(userInfo.UserID);
                userToUpdate.UserID = userInfo.UserID;
                userToUpdate.LastName = userInfo.LastName;
                userToUpdate.FirstName = userInfo.FirstName;
                userToUpdate.Patronymic = userInfo.Patronymic;
                if (userToUpdate.Password == userInfo.Password) //password supplied is crypted already
                {
                    //do nothing - passwords already the same
                }
                else
                {
                    userToUpdate.Password = Crypter.Blowfish.Crypt(userInfo.Password);
                }
                if (!Util.IsValidEmail(userInfo.Email))
                    throw new ArgumentException("Email string is not a valid email!");
                userToUpdate.Email = userInfo.Email;
                userToUpdate.Phone = userInfo.Phone;
                userToUpdate.DateOfBirth = userInfo.DoB;

                context.SaveChanges();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Updates a user
        /// </summary>
        /// <param name="u">New passwords supplied should be plain text!</param>
        public static void UpdateUser(UserInfo u)
        {
            using (SchoolJournalEntities context = new SchoolJournalEntities())
            {
                User userToUpdate = (User)context.Set<User>().Find(u.UserID);

                if(userToUpdate==null)
                    throw new ArgumentException("UserID is incorrect!");
                userToUpdate.FirstName = u.FirstName;
                userToUpdate.LastName = u.LastName;
                userToUpdate.Patronymic = u.Patronymic;
                userToUpdate.DateOfBirth = u.DoB;
                if (!Util.IsValidEmail(u.Email))
                    throw new ArgumentException("Email string is not a valid email!");
                userToUpdate.Email = u.Email;
                if (userToUpdate.Password != u.Password) //new password supplied => crypt it!
                {
                    userToUpdate.Password = Crypter.Blowfish.Crypt(u.Password);
                }
                userToUpdate.Phone = u.Phone;

                context.SaveChanges();
            }
        }