コード例 #1
0
        public static User GetCurrentUser()
        {
            var user = new User();

            string currentUserName = String.Empty;

            IPrincipal currentUser = null;
            HttpContext current = HttpContext.Current;
            if (current != null)
                currentUser = current.User;

            if ((currentUser != null) && (currentUser.Identity != null))
                currentUserName = currentUser.Identity.Name;

            using (var db = new TrackerDataContext())
            {
                db.ObjectTrackingEnabled = false;
                user = db.User.GetByEmailAddress(currentUserName);
            }

            return user;
        }
コード例 #2
0
        //
        // GET: /User/Details/5

        public ActionResult Details(int id)
        {
            Data.User user = null;
            using (var db = new TrackerDataContext())
            {
                var options = new DataLoadOptions();
                options.LoadWith <Data.User>(u => u.UserRoleList);
                options.LoadWith <Data.UserRole>(r => r.Role);
                db.LoadOptions = options;

                user = db.User.GetByKey(id);
            }

            if (null == user)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(user));
            }
        }
コード例 #3
0
 public UserViewData GetData(User user)
 {
     var userViewData = new UserViewData();
     userViewData.User = user;
     using (var db = new TrackerDataContext())
     {
         userViewData.Roles = UIHelper.GetRoleSelectList(null, user.RoleList.ToList());
         userViewData.Audits = UIHelper.TransformAudits(db.Audit.ByUserId(user.Id).OrderByDescending(a => a.Date).ToList());
     }
     return userViewData;
 }
コード例 #4
0
        private void CreateUsers()
        {
            var user = new User()
            {
                FirstName = "Spock",
                LastName = "Sarekson",
                PasswordHash = "aM/Vndh7cYd3Mxq7msArjl9YU8zoR6fF+sVTSUCcsJi2bx+cwOI0/Bkr5hfq9vYfTe3/rlgPpSMg108acpw+qA",
                PasswordSalt = "=Unc%",
                EmailAddress = "*****@*****.**",
                IsApproved = true
            };

            using (var db = new TrackerDataContext { Log = Console.Out })
            {
                db.User.InsertOnSubmit(user);
                db.SubmitChanges();
                SpockId = user.Id;
            }

            var users = new List<User>();

            users.Add(new User()
            {
                FirstName = "James",
                LastName = "Kirk",
                PasswordHash = "aM/Vndh7cYd3Mxq7msArjl9YU8zoR6fF+sVTSUCcsJi2bx+cwOI0/Bkr5hfq9vYfTe3/rlgPpSMg108acpw+qA",
                PasswordSalt = "=Unc%",
                EmailAddress = "*****@*****.**",
                IsApproved = true
            });

            users.Add(new User()
            {
                FirstName = "Bones",
                LastName = "McCoy",
                PasswordHash = "aM/Vndh7cYd3Mxq7msArjl9YU8zoR6fF+sVTSUCcsJi2bx+cwOI0/Bkr5hfq9vYfTe3/rlgPpSMg108acpw+qA",
                PasswordSalt = "=Unc%",
                EmailAddress = "*****@*****.**",
                IsApproved = false
            });

            users.Add(new User()
            {
                FirstName = "Nyota",
                LastName = "Uhura",
                PasswordHash = "aM/Vndh7cYd3Mxq7msArjl9YU8zoR6fF+sVTSUCcsJi2bx+cwOI0/Bkr5hfq9vYfTe3/rlgPpSMg108acpw+qA",
                PasswordSalt = "=Unc%",
                EmailAddress = "*****@*****.**",
                IsApproved = false
            });

            users.Add(new User()
            {
                FirstName = "Ellen",
                LastName = "Tigh",
                PasswordHash = "aM/Vndh7cYd3Mxq7msArjl9YU8zoR6fF+sVTSUCcsJi2bx+cwOI0/Bkr5hfq9vYfTe3/rlgPpSMg108acpw+qA",
                PasswordSalt = "=Unc%",
                EmailAddress = "*****@*****.**",
                IsApproved = false
            });

            using (var db = new TrackerDataContext { Log = Console.Out })
            {
                db.User.InsertAllOnSubmit(users);
                db.SubmitChanges();
                JamesId = db.User.ByFirstName("James").ByLastName("Kirk").First().Id;
            }
        }
コード例 #5
0
 public void Test_Rules()
 {
     int brokenRules = 0;
     try
     {
         using (var db = new TrackerDataContext { Log = Console.Out })
         {
             User user = new User();
             user.EmailAddress = "*****@*****.**";
             db.User.InsertOnSubmit(user);
             db.SubmitChanges();
         }
     }
     catch (BrokenRuleException e)
     {
         brokenRules = e.BrokenRules.Count;
         Console.Write(e.ToString());
     }
     Assert.AreEqual(brokenRules, 5);
 }
コード例 #6
0
 partial void OnUserChanging(User value);
コード例 #7
0
 private void OnUserListRemove(User entity)
 {
     SendPropertyChanging(null);
     var userRole = UserRoleList.FirstOrDefault(c => c.RoleId == Id
         && c.UserId == entity.Id);
     UserRoleList.Remove( userRole);
     SendPropertyChanged(null);
 }
コード例 #8
0
 private void OnUserListAdd(User entity)
 {
     SendPropertyChanging(null);
     UserRoleList.Add(new UserRole { Role = this, User = entity });
     SendPropertyChanged(null);
 }
コード例 #9
0
 partial void OnCreatedUserChanging(User value);
コード例 #10
0
 partial void OnAssignedUserChanging(User value);
コード例 #11
0
        public void AuditLog()
        {
            var db = new TrackerDataContext { Log = Console.Out };
            db.AuditingEnabled = true;

            var user = new User();
            user.EmailAddress = string.Format("test.{0}@test.com", DateTime.Now.Ticks);
            user.FirstName = "Test";
            user.IsApproved = true;
            user.LastName = "User";
            user.PasswordHash = "asdf";
            user.PasswordSalt = "asdf";

            db.User.InsertOnSubmit(user);
            db.SubmitChanges();

            var auditLog = db.LastAudit;
            Assert.IsNotNull(auditLog);
        }