本文整理汇总了C#中Models.User类的典型用法代码示例。如果您正苦于以下问题:C# User类的具体用法?C# User怎么用?C# User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
User类属于Models命名空间,在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadUserPostsTest
public void ReadUserPostsTest()
{
// act
string input = "Bob";
var user = new User { UserId = Guid.NewGuid(), Username = input };
var output = new StringBuilder();
output.AppendLine("Good game though. (1 minute(s) ago)");
output.AppendLine("Damn! We lost! (2 minute(s) ago)");
var messages = new List<Message>
{
new Message { Description = "Good game though.", PostedDt = DateTime.UtcNow.AddMinutes(-1)},
new Message { Description = "Damn! We lost!", PostedDt = DateTime.UtcNow.AddMinutes(-2)}
};
_userManagerMock.Setup(x => x.GetUserByUsername(user.Username, true)).Returns(user);
_messageManagerMock.Setup(x => x.GetMessages(user)).Returns(messages);
var read = new Read(_userManagerMock.Object, _messageManagerMock.Object);
// actual
var actual = read.Perform(input);
// assert
Assert.AreEqual(actual, output.ToString());
_messageManagerMock.Verify(x => x.GetMessages(user), Times.Once);
}
示例2: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
using(var db= new ELearningContext())
{
User userr= new User(){UserName=model.UserName, Password= model.Password};
db.Users.Add(userr);
db.SaveChanges();
}
var user = new ApplicationUser() { UserName = model.UserName };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
示例3: Main
static void Main(string[] args)
{
using (IRiakEndPoint endpoint = RiakCluster.FromConfig("riakConfig"))
{
IRiakClient client = endpoint.CreateClient();
UserRepository userRepo = new UserRepository(client);
MsgRepository msgRepo = new MsgRepository(client);
TimelineRepository timelineRepo = new TimelineRepository(client);
TimelineManager timelineMgr = new TimelineManager(timelineRepo, msgRepo);
// Create and save users
var marleen = new User("marleenmgr", "Marleen Manager", "[email protected]");
var joe = new User("joeuser", "Joe User", "[email protected]");
userRepo.Save(marleen);
userRepo.Save(joe);
// Create new Msg, post to timelines
Msg msg = new Msg(marleen.UserName, joe.UserName, "Welcome to the company!");
timelineMgr.PostMsg(msg);
// Get Joe's inbox for today, get first message
Timeline joesInboxToday = timelineMgr.GetTimeline(joe.UserName, Timeline.TimelineType.Inbox, DateTime.UtcNow);
Msg joesFirstMsg = msgRepo.Get(joesInboxToday.MsgKeys.First());
Console.WriteLine("From: " + joesFirstMsg.Sender);
Console.WriteLine("Msg : " + joesFirstMsg.Text);
}
}
示例4: btn_Login_Click
private async void btn_Login_Click(object sender, EventArgs e)
{
var user = new User
{
Account = this.textBox_Account.Text,
Password = this.textBox_Password.Text
};
try
{
var state = await RemoteServer.Instance.Login(user, false);
if (state == false)
{
MessageBox.Show("账号或密码错误...", "系统提示");
}
else
{
this.Hide();
new SumForm().ShowDialog();
this.Close();
}
}
catch (TimeoutException ex)
{
this.Text = ex.Message;
}
catch (RemoteException ex)
{
MessageBox.Show(ex.Message, "远程服务器异常");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "未分类的异常");
}
}
示例5: SeedUser
public void SeedUser(UserSeedModel model, HomeGrownBulgariaDbContext context)
{
if (!context.Users.Any(u => u.UserName == model.Username))
{
var userStore = new UserStore<User>(context);
var userManager = new UserManager<User>(userStore);
var user = new User
{
UserName = model.Username,
Email = model.Username,
FirstName = model.FirstName,
LastName = model.LastName,
AverageRatingReceived = ValidationConstants.AverageRatingInitialValue,
City = model.City
};
IdentityResult result = userManager.Create(user, model.Password);
if (!result.Succeeded)
{
throw new OperationCanceledException(result.Errors.First());
}
if (model.Role != null)
{
userManager.AddToRole(user.Id, model.Role);
}
context.SaveChanges();
}
}
示例6: SeedAdmin
internal static void SeedAdmin(SciHubDbContext context)
{
const string adminUserName = "theDecider666";
const string adminPassword = "deciderd";
if (context.Users.Any(u => u.UserName == adminUserName))
{
return;
}
var userManager = new UserManager<User>(new UserStore<User>(context));
var admin = new User
{
UserName = adminUserName,
Email = "[email protected]",
FirstName = "Admin",
LastName = "Adminos",
Avatar = UserDefaultPictureConstants.Female,
Gender = Gender.Female,
About = "I am the Decider!"
};
userManager.Create(admin, adminPassword);
userManager.AddToRole(admin.Id, UserRoleConstants.Admin);
userManager.AddToRole(admin.Id, UserRoleConstants.Default);
context.SaveChanges();
}
示例7: Main
public static void Main()
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<ErisSystemContext, Data.Migrations.EfConfiguration>());
Importer.ImportCountries();
var db = new ErisSystemContext();
var date = new DateTime(1991, 01, 01);
var country = db.Countries.Find(3);
var hitman = new User();
hitman.AboutMe = "Thug life";
hitman.UserName = "Bono";
hitman.PasswordHash = "[email protected]#@[email protected][email protected]";
hitman.DateOfBirth = date;
hitman.CountriesOfOperation.Add(country);
db.Users.AddOrUpdate(hitman);
db.SaveChanges();
var repositoryTest = new EfGenericRepository<User>(db);
var hitmen = repositoryTest.All();
foreach (var x in hitmen)
{
Console.WriteLine(x.UserName);
Console.WriteLine(x.Gender);
Console.WriteLine(x.AboutMe);
Console.WriteLine(x.DateOfBirth);
}
}
示例8: btnServiceReference_Click
private void btnServiceReference_Click(object sender, EventArgs e)
{
try
{
string idString = txtUserId.Text;
int id = int.Parse(idString);
User user;
using (var service = new UsersService.UsersServiceSoapClient())
{
// Service References add it's own classes to match the ones in the Web Service
UsersService.User serviceUser = service.GetUser(id);
if (serviceUser == null)
{
throw new Exception("User not found.");
}
user = new User
{
Id = serviceUser.Id,
Name = serviceUser.Name
};
}
userName.Text = user.Name;
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例9: PerformPostMessageOnExistingUserTest
public void PerformPostMessageOnExistingUserTest()
{
// act
string input = "Bob -> Good game though.";
User user = new User
{
UserId = Guid.NewGuid(),
Username = "Bob"
};
Message userMessage = new Message
{
UserId = user.UserId
};
_userManagerMock.Setup(x => x.GetUserByUsername(user.Username, false)).Returns(user);
_messageManagerMock.Setup(x => x.AddMessage(user.UserId, input));
var perform = new Post(_userManagerMock.Object, _messageManagerMock.Object);
// actual
var actual = perform.Perform(input);
// assert
Assert.AreEqual(actual, string.Empty);
_userManagerMock.Verify(x => x.AddUser(It.IsAny<string>()), Times.Never);
_messageManagerMock.Verify(x => x.AddMessage(It.IsAny<Guid>(), It.IsAny<string>()), Times.AtLeastOnce);
}
示例10: PerformPostNewMessageOnNewUserTest
public void PerformPostNewMessageOnNewUserTest()
{
// act
string input = "Alice -> I love the weather today";
var user = new User
{
UserId = Guid.NewGuid(),
Username = "Alice"
};
_userManagerMock.Setup(x => x.GetUserByUsername(user.Username, false)).Returns((User) null);
_userManagerMock.Setup(x => x.AddUser(user.Username)).Returns(user);
_messageManagerMock.Setup(x => x.AddMessage(user.UserId, input));
var perform = new Post(_userManagerMock.Object, _messageManagerMock.Object);
// actual
var actual = perform.Perform(input);
// assert
Assert.AreEqual(actual, string.Empty);
_userManagerMock.Verify(x=>x.AddUser(It.IsAny<string>()), Times.Once);
_messageManagerMock.Verify(x=>x.AddMessage(It.IsAny<Guid>(),It.IsAny<string>()), Times.AtLeastOnce);
}
示例11: Import
public override void Import(BGTouristGuideDbContext db)
{
PasswordHasher hasher = new PasswordHasher();
User admin = new User
{
Email = "[email protected]",
UserName = "admin",
FirstName = "Admin",
LastName = "Admin",
PasswordHash = hasher.HashPassword("admin"),
RegistrationDate = DateTime.Now,
SecurityStamp = Guid.NewGuid().ToString()
};
db.Users.Add(admin);
IdentityUserRole adminRole = new IdentityUserRole();
var dbadminRole = db.Roles.Where(r => r.Name == DatabaseConstants.AdminUserRole).FirstOrDefault();
adminRole.UserId = admin.Id;
adminRole.RoleId = dbadminRole.Id;
dbadminRole.Users.Add(adminRole);
db.SaveChanges();
}
示例12: add
public void add()
{
if(IsAjaxRequest) CancelLayout();
PropertyBag["u"] = new User();
RenderView("addoredit");
}
示例13: SignUp
public MembershipCreateStatus SignUp(string userName, string password, string email)
{
var user = new User { Name = userName, PasswordHash = password, Email = email };
return !Repository.AddUser(user)
? MembershipCreateStatus.DuplicateUserName
: MembershipCreateStatus.Success;
}
示例14: SeedData
public void SeedData(EmployerEmployeeHuntDbContext context)
{
var userStore = new UserStore<User>(context);
var userManager = new UserManager<User>(userStore);
var adminUser = new User
{
UserName = AdministratorUserName,
Email = AdministratorUserName
};
var headhunterUser = new User
{
UserName = HeadhunterUserName,
Email = HeadhunterUserName
};
var developerUser = new User
{
UserName = DeveloperUserName,
Email = DeveloperUserName
};
var employerUser = new User
{
UserName = EmployerUserName,
Email = EmployerUserName
};
userManager.Create(adminUser, AdministratorPassword);
userManager.Create(headhunterUser, HeadhunterPassword);
userManager.Create(developerUser, DeveloperPassword);
userManager.Create(employerUser, EmployerPassword);
userManager.AddToRole(adminUser.Id, GlobalConstants.AdministratorRoleName);
userManager.AddToRole(headhunterUser.Id, GlobalConstants.HeadhunterRoleName);
userManager.AddToRole(developerUser.Id, GlobalConstants.UserRoleName);
userManager.AddToRole(employerUser.Id, GlobalConstants.UserRoleName);
for (int i = 0; i < 60; i++)
{
var currentUser = new User
{
Email = string.Format("user_{0}@somemail.com", i + 1),
UserName = string.Format("user_{0}", i + 1)
};
userManager.Create(currentUser, currentUser.Email);
if (i % 2 == 0)
{
userManager.AddToRole(currentUser.Id, GlobalConstants.HeadhunterRoleName);
}
else
{
userManager.AddToRole(currentUser.Id, GlobalConstants.UserRoleName);
}
}
}
示例15: CalculateUserDamage
public static double CalculateUserDamage(User attacker, User defender)
{
double attack = CalculateUserAttack(attacker);
double defence = CalculateUserDefence(defender);
double modifier = CalculateModifier();
double damage = (((2 * modifier + 100) / 20) * ((attack / defence) / 10) + 2) * (10 / modifier);
return Math.Round(damage, 2);
}