Esempio n. 1
0
        public void TestAddUpdateAndDeleteUser()
        {
            UniUser user = new UniUser();
            user.FirstName = "Test1";
            user.SurName = "Tester";
            user.EmailAddress = "*****@*****.**";
            user.PermissionLevelId = 1;
            user.IsActive = true;
            user.CreatedDate = DateTime.Now;
            user.EnrolementYear = new DateTime(2014, 01, 01);

            int userId = _repository.AddOrUpdate(user);
            Assert.AreNotEqual(0, userId);
            user = _repository.GetById(userId);
            UniUser newUser = new UniUser();
            newUser.UserId = user.UserId;
            newUser.FirstName = "Test2";
            newUser.SurName = "Tester";
            newUser.EmailAddress = "*****@*****.**";
            newUser.PermissionLevelId = 1;
            newUser.IsActive = true;
            newUser.CreatedDate = DateTime.Now;
            newUser.EnrolementYear = new DateTime(2014, 01, 01);

            int userId2 = _repository.AddOrUpdate(newUser);
            Assert.AreEqual(userId, userId2);
            user = _repository.GetById(userId);
            Assert.AreEqual("Test2", user.FirstName);
            bool userRemoved = _repository.Remove(user);
            Assert.IsTrue(userRemoved);
        }
Esempio n. 2
0
 public int AddOrUpdate(UniUser user)
 {
     try
     {
         using (UniUserDbContext db = new UniUserDbContext(ConnectionString))
         {
             db.UniUsers.AddOrUpdate(user);
             db.SaveChanges();
             return user.UserId;
         }
     }
     catch (Exception e)
     {
         if (user == null)
         {
             throw new Exception("Error Adding Updating User: User null", e);
         }
         throw new Exception(
             "Error Adding/Updating User: {Id:" + user.UserId + " Email:" + user.EmailAddress + "}", e);
     }
 }
Esempio n. 3
0
 public bool Remove(UniUser user)
 {
     try
     {
         using (UniUserDbContext db = new UniUserDbContext(ConnectionString))
         {
             db.UniUsers.Attach(user);
             db.UniUsers.Remove(user);
             db.SaveChanges();
             return true;
         }
     }
     catch (Exception e)
     {
         if (user == null)
         {
             throw new Exception("Error Removing User: User null", e);
         }
         throw new Exception("Error Removing User: {Id:" + user.UserId + " Email:" + user.EmailAddress + "}", e);
     }
 }