本文整理汇总了C#中UserRepository.GetAll方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.GetAll方法的具体用法?C# UserRepository.GetAll怎么用?C# UserRepository.GetAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.GetAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var dbContext = new ApplicationDbContext();
using (var uow = new UnitOfWork(dbContext))
{
// Creating user
// var user1 = new User { Login = "Anna", Password = "123" };
// var userRepo = new UserRepository(dbContext);
//userRepo.Create(user1);
//uow.Commit();
var userRepo = new UserRepository(dbContext);
var user1 = new User { Login = "Anna1", Password = "123" };
var user2 = new User { Login = "Anna2", Password = "123" };
// userRepo.Create(user1);
//userRepo.Create(user2);
// uow.Commit();
var users = userRepo.GetAll();
Console.WriteLine("All users count: " + users.Count());
var anna = userRepo.GetBy(user1.Login);
userRepo.Delete(anna);
uow.Commit();
users = userRepo.GetAll();
Console.WriteLine("All filtered users count: " + users.Count());
Console.ReadLine();
// Creating user article
var article1 = new Article { Title = "Article1", Body = "Article1 BodyText" };
var anna2 = userRepo.GetBy(user2.Login);
userRepo.Delete(anna2);
// anna2.Articles.Add(article1);
uow.Commit();
/*var comment1 = new Comment { Body = "Article1 is my first arctile. (Anna)" };
var articleRepo = new ArticleRepository(dbContext);
anna2.Comments.Add(comment1);
article1.Comments.Add(comment1);
uow.Commit();*/
}
}
示例2: Remove_Entity_Test
public static void Remove_Entity_Test()
{
IUserRepository repository = new UserRepository(_session);
ICollection<User> todosAntesDeDelete = repository.GetAll();
foreach (User User in todosAntesDeDelete)
{
repository.Delete(User);
}
ICollection<User> todosDepoisDeDelete = repository.GetAll();
Assert.IsTrue(todosDepoisDeDelete.Count == 0);
}
示例3: AddUser
public void AddUser()
{
using (CapriconContext context = new CapriconContext())
{
var newUser = new User()
{
FirstName = "james",
LastName = "kamau",
OtherName = "",
Gender = Gender.Female,
MobilePhone = "0756 123 456",
Email = "[email protected]",
Town = "Nairobi",
District = "Nairobi",
DateOfBirth = DateTime.Now.AddYears(-40),
};
var userRep = new UserRepository(context);
userRep.Add(newUser);
try
{
context.SaveChanges();
}
catch (DbEntityValidationException ex)
{
//Retrieve validation errors
ex.EntityValidationErrors.ToList().ForEach
(
v =>
{
v.ValidationErrors.ToList().ForEach
(
e =>
{
System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
}
);
}
);
Assert.Fail("Test failed");
}
//retrieve saved object
var context1 = new CapriconContext();
var repository = new UserRepository(context1);
var savedUsers = repository.GetAll().ToList();
Assert.AreEqual(savedUsers.Count(), 1, "returns 20 records");
var savedUsersList = savedUsers;
savedUsersList.ForEach
(
s =>
{
Debug.WriteLine(s.UserId +" - "+ s.FirstName +" "+ s.LastName);
}
);
};
}
示例4: AddUserMessage
public void AddUserMessage()
{
using (var uow = new CapriconContext())
{
//retreive an existing user
var userRepository = new UserRepository(uow);
var existingUser = userRepository.GetAll().FirstOrDefault();
Assert.IsNotNull(existingUser);
//retreive an existing message
var messageRepository = new MessageRepository(uow);
var existingMessage = messageRepository.GetAll().FirstOrDefault();
Assert.IsNotNull(existingMessage);
//create new user messsage
var newUserMessage = new UserMessage()
{
User = existingUser,
Message = existingMessage
};
//add the new user message to the repository
var userMessageRepository = new UserMessageRepository(uow);
userMessageRepository.Add(newUserMessage);
try
{
uow.SaveChanges();
}
catch (DbEntityValidationException ex)
{
//Retrieve validation errors
ex.EntityValidationErrors.ToList().ForEach
(
v =>
{
v.ValidationErrors.ToList().ForEach
(
e =>
{
System.Diagnostics.Debug.WriteLine(e.ErrorMessage);
}
);
}
);
Assert.Fail("Test failed");
}
//retrieve saved object
var uow1 = new CapriconContext();
var repository = new UserMessageRepository(uow1);
var savedUserMessages = repository.GetAll().ToList();
Assert.AreEqual(savedUserMessages[0].User.FirstName, existingUser.FirstName = "james");
Assert.AreEqual(savedUserMessages[0].Message.MessageId, existingMessage.MessageId = 1);
};
}
示例5: GetMySql
public static void GetMySql()
{
UserRepository rep = new UserRepository(new MySqlDbContext());
rep.Insert(new User { ID = new Guid("12736219-9398-4DBD-A392-BF8C5CCC3635"), Mobile = "01819421877", Password = "NewPassword", Username = "SiamDeath" });
rep.Commit();
var data = rep.Get(new Guid("C1C8D804-0645-4006-B9C8-192EBD944944"));
var collection = rep.GetAll().ToList();
}
示例6: Index
public ActionResult Index()
{
var test = WebSecurity.CurrentUserName;
var db = new GazDbContext();
var repo = new UserRepository(db);
var users = repo.GetAll();
return View(users);
}
示例7: ListAdmins
public ActionResult ListAdmins()
{
AdminListAdminsVM model = new AdminListAdminsVM();
UserRepository<Administrator> adminRepo = new UserRepository<Administrator>();
model.Administrators = adminRepo.GetAll();
return View(model);
}
示例8: GetSql
public static void GetSql()
{
UserRepository rep = new UserRepository(new WebApiDBContext());
rep.Insert(new User { ID = new Guid("19D40AEC-37B7-4114-A5BF-E4E3B3CFC97A"), Mobile = "01819421877", Password = "NewPassword", Username = "SiamDeath" });
rep.Commit();
var data = rep.Get(new Guid("C1C8D804-0645-4006-B9C8-192EBD944944"));
var collection = rep.GetAll().ToList();
}
示例9: GetUsers
public JsonResult GetUsers(DataTablesRequest model)
{
string dataPath = ConfigurationManager.AppSettings["UsersPath"];
var repo = new UserRepository(dataPath);
var data = repo.GetAll().AsQueryable();
var dataTableParser = new DataTablesParser<User>(model, data);
var formattedList = dataTableParser.Process();
return Json(formattedList, JsonRequestBehavior.AllowGet);
}
示例10: WhenGetAllFromEmptyDatabase_ThenReturnsEmptyCollection
public void WhenGetAllFromEmptyDatabase_ThenReturnsEmptyCollection()
{
this.InitializeFixture();
var repository = new UserRepository(new DatabaseFactory());
IEnumerable<User> actual = repository.GetAll();
Assert.NotNull(actual);
var actualList = new List<User>(actual);
Assert.Equal(0, actualList.Count);
}
示例11: Get
public IEnumerable<User> Get()
{
string userName = Thread.CurrentPrincipal.Identity.Name;
var userDataContext = new UserDataContext();
var userRepository = new UserRepository(userDataContext);
IQueryable<User> allUsers = userRepository.GetAll();
var result = allUsers.ToList();
return result;
}
示例12: Index
public ActionResult Index()
{
AdministratorIndexVM model = new AdministratorIndexVM();
UserRepository<Teacher> tRepo = new UserRepository<Teacher>();
UserRepository<Student> sRepo = new UserRepository<Student>();
UserRepository<Administrator> aRepo = new UserRepository<Administrator>();
model.CountTeachers = tRepo.GetAll().Count();
model.CountStudents = sRepo.GetAll().Count();
model.CountAdministrators = aRepo.GetAll().Count();
return View(model);
}
示例13: RateSong
public void RateSong(SongRatingDto rating, string userName)
{
using (SmartPlayerEntities context = new SmartPlayerEntities())
{
UserRepository userRepo = new UserRepository(context);
User currentUser = userRepo.GetAll().First(x => x.Email == userName);
context.UserSongVotes.Add(new UserSongVote()
{
Rating = rating.Rating,
SongId = rating.SongId,
UserId = currentUser.Id
});
context.SaveChanges();
}
}
示例14: GetUser
public override MembershipUser GetUser(string username, bool userIsOnline)
{
if(currUser == null){
var dbcxt = new GazSimpleUsersDbContext();
var urepo = new UserRepository(dbcxt);
currUser = urepo.GetAll().FirstOrDefault(u => u.Username == username);
if(currUser != null) return null;
MembershipUser user = new MembershipUser(currUser.FirstName, currUser.FirstName, null, currUser.Email, string.Empty,
string.Empty, true, false, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now, DateTime.Now);
return user;
}
return null;
}
示例15: AddGrade
public ActionResult AddGrade(int studentID, int subjectID)
{
GradeAddGradeVM model = new GradeAddGradeVM();
UserRepository<Student> sRepo = new UserRepository<Student>();
SubjectRepository subjRepo = new SubjectRepository();
GradeRepository gRepo = new GradeRepository();
Student student = sRepo.GetAll(filter: s => s.ID == studentID && s.Course.CourseSubject.Any(sub => sub.SubjectID == subjectID)).FirstOrDefault();
Subject subject = subjRepo.GetByID(subjectID);
Grade grade = gRepo.GetAll(filter: g => g.StudentID == student.ID).FirstOrDefault();
model.StudentID = student.ID;
model.SubjectID = subject.ID;
return View(model);
}