本文整理汇总了C#中UserRepository.GetUserByName方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.GetUserByName方法的具体用法?C# UserRepository.GetUserByName怎么用?C# UserRepository.GetUserByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.GetUserByName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Show
public ActionResult Show(string id)
{
var userRepo = new UserRepository(new DataContext());
User user = userRepo.GetUserByName(id);
User me = userRepo.GetUserByName(User.Identity.Name);
ViewBag.CurrentUser = user;
ViewBag.IsFriends = me.Friends.FirstOrDefault(u => u.FriendId == user.ID) != null;
if (user != null)
{
ViewBag.LastMessage = user.Barks.OrderByDescending(o => o.CreateAt).First();
//return View(user);
return View(barkRepository.GetBarksByUser(user.ID).OrderByDescending(t => t.CreateAt));
}
return RedirectToAction("Index");
}
示例2: ShouldReturnNullWhenUserDoesntExists
public void ShouldReturnNullWhenUserDoesntExists()
{
var repo = new UserRepository();
repo.CreateUser("some_name", "password", "name", "address", "phone");
var user = repo.GetUserByName("other_name");
Assert.IsNull(user);
}
示例3: Index
public ActionResult Index()
{
var userRepo = new UserRepository(new DataContext());
User user = userRepo.GetUserByName(User.Identity.Name);
ViewBag.Followers = userRepo.FollowersCount(user);
ViewBag.CurrentUser = user;
ViewBag.LastMessage = user.Barks.OrderByDescending(o=>o.CreateAt).First();
//return View(user);
return View(barkRepository.GetBarksByUser(user.ID).OrderByDescending(t => t.CreateAt));
}
示例4: ShouldReturnUserByAccountName
public void ShouldReturnUserByAccountName()
{
const string accountName = "user_name";
var repo = new UserRepository();
repo.CreateUser(accountName, "password", "name", "address", "phone");
var user = repo.GetUserByName(accountName);
Assert.IsNotNull(user);
Assert.AreEqual(accountName,user.AccountName);
}
示例5: Bark
public ActionResult Bark(string message)
{
var userRepo = new UserRepository(new DataContext());
User user = userRepo.GetUserByName(User.Identity.Name);
var model = new Bark();
model.Message = message;
model.CreateAt = DateTime.Now;
model.UserID = user.ID;
if (ModelState.IsValid)
{
barkRepository.InsertBark(model);
barkRepository.Save();
}
return RedirectToAction("", "Home");
}
示例6: TaggleFollow
public ActionResult TaggleFollow(string id)
{
var userRepo = new UserRepository(new DataContext());
User me = userRepo.GetUserByName(User.Identity.Name);
User friend = userRepo.GetUserByID(Guid.Parse(id));
//var Friends = me.Friends.FirstOrDefault(u => u.FriendId == user.ID);
if (me.IsFriends(friend))
{
me.RemoveFriend(friend);
}
else
{
me.AddFriend(friend);
}
userRepo.Save();
return RedirectToAction("Show", new {id = friend.Username});
}
示例7: UserDetails
public ActionResult UserDetails()
{
var userRepo = new UserRepository(new DataContext());
User user = userRepo.GetUserByName(User.Identity.Name);
List<UserFriend> friends = userRepo.FollowersCount(user);
UserDetailsModel model = new UserDetailsModel { User = user, Followers = friends };
return PartialView("_SideContents", model);
}