Example #1
0
File: User.cs Project: Crisp771/Chc
        public User CreateUser(int userid)
        {
            var hash      = System.Security.Cryptography.SHA1.Create();
            var encoder   = new System.Text.ASCIIEncoding();
            var combined  = encoder.GetBytes(this.Password ?? "");
            var hashvalue = BitConverter.ToString(hash.ComputeHash(combined)).ToLower().Replace("-", "");

            var t = new tblUser()
            {
                Deleted  = this.Deleted,
                Password = hashvalue,
                RoleID   = this.RoleID,
                Username = this.Username
            };

            _context.tblUsers.Add(t);
            _context.SaveChanges();

            var audit = new UserAudit(_context);

            audit.CarriedOutByUserID = userid;
            audit.Event         = "User Created.";
            audit.EventDateTime = DateTime.Now;
            audit.UserID        = t.UserID;
            audit.Audit();

            return(new ChcObjects.User(t));
        }
Example #2
0
File: User.cs Project: Crisp771/Chc
        public User UpdateUser(int userid)
        {
            var user = (_context.tblUsers.Find(this.UserID));

            if (user.Username != this.Username)
            {
                var audit = new UserAudit(_context);
                audit.CarriedOutByUserID = userid;
                audit.Event         = string.Format("Username changed from {0} to {1}.", user.Username, this.Username);
                audit.EventDateTime = DateTime.Now;
                audit.UserID        = this.UserID;
                audit.Audit();
                user.Username = this.Username;
            }

            if (user.RoleID != this.RoleID)
            {
                user.RoleID = this.RoleID;
            }

            if (!string.IsNullOrEmpty(this.Password))
            {
                var audit = new UserAudit(_context);
                audit.CarriedOutByUserID = userid;
                audit.Event         = string.Format("Password Changed.");
                audit.EventDateTime = DateTime.Now;
                audit.UserID        = this.UserID;
                audit.Audit();

                var hash      = System.Security.Cryptography.SHA1.Create();
                var encoder   = new System.Text.ASCIIEncoding();
                var combined  = encoder.GetBytes(this.Password ?? "");
                var hashvalue = BitConverter.ToString(hash.ComputeHash(combined)).ToLower().Replace("-", "");

                user.Password = hashvalue;
            }

            if (user.Deleted != this.Deleted)
            {
                user.Deleted = this.Deleted;
            }

            _context.SaveChanges();

            return(new User(user));
        }