• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Models.User类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Models.User的典型用法代码示例。如果您正苦于以下问题:C# User类的具体用法?C# User怎么用?C# User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



User类属于Models命名空间,在下文中一共展示了User类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
        }
开发者ID:hkshambesh,项目名称:Codurence-Social-Network-ConsoleApp,代码行数:28,代码来源:ReadCommandTests.cs


示例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);
        }
开发者ID:barbuandrei,项目名称:nutella,代码行数:26,代码来源:AccountController.cs


示例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);
            }
        }
开发者ID:vixletadmin,项目名称:taste-of-riak,代码行数:28,代码来源:Program.cs


示例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, "未分类的异常");
            }
        }
开发者ID:wang-yong,项目名称:NetworkSocket,代码行数:35,代码来源:MainForm.cs


示例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();
            }
        }
开发者ID:InKolev,项目名称:HomeGrownBulgaria,代码行数:31,代码来源:UsersSeeder.cs


示例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();
        }
开发者ID:Vyara,项目名称:SciHub,代码行数:29,代码来源:DataSeeder.cs


示例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);
            }
        }
开发者ID:ERIS-Team-TelerikAcademy,项目名称:ERIS-App,代码行数:34,代码来源:StartUp.cs


示例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);
     }
 }
开发者ID:israel-munoz,项目名称:dotnet-webservice,代码行数:28,代码来源:Main.cs


示例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);
        }
开发者ID:hkshambesh,项目名称:Codurence-Social-Network-ConsoleApp,代码行数:28,代码来源:PostCommandTests.cs


示例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);
        }
开发者ID:hkshambesh,项目名称:Codurence-Social-Network-ConsoleApp,代码行数:26,代码来源:PostCommandTests.cs


示例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();
        }
开发者ID:TsvetanMilanov,项目名称:BG-Tourist-Guide-Server,代码行数:27,代码来源:UsersDataImporter.cs


示例12: add

        public void add()
        {
            if(IsAjaxRequest) CancelLayout();

            PropertyBag["u"] = new User();
            RenderView("addoredit");
        }
开发者ID:nshah55,项目名称:storm-the-castle,代码行数:7,代码来源:UserManagerUserController.cs


示例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;
 }
开发者ID:dominiqueplante,项目名称:Chirper,代码行数:7,代码来源:AuthentificationService.cs


示例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);
                }
            }
        }
开发者ID:TsvetanMilanov,项目名称:Employer-Employee-Hunt,代码行数:59,代码来源:UsersDataImporter.cs


示例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);
 }
开发者ID:Shkembe-Chorba-Team,项目名称:JustWars,代码行数:8,代码来源:BattleController.cs


示例16: AddOrUpdate

        public void AddOrUpdate(User user)
        {
            if (user == null)
                throw new ArgumentNullException("user");
            if (user.Identifier == Guid.Empty)
                user.Identifier = Guid.NewGuid();

            _users.AddOrUpdate(user.FacebookId, user, (key, oldValue) => user);
        }
开发者ID:prabirshrestha,项目名称:NancyFacebookSample,代码行数:9,代码来源:InMemoryAppUserMapper.cs


示例17: Check_AddUser

        public void Check_AddUser()
        {
            var editUser = new User { UserName = "new"};
            var userStore = new UserStore(_databaseContextMock.Object);
            userStore.EditUser(editUser, 1);

            var result = userStore.GetById(1);

            Assert.AreEqual("new", result.UserName);
        }
开发者ID:AnnaKerina,项目名称:TrainingProject,代码行数:10,代码来源:UserStoreTests.cs


示例18: Convert

        public static User Convert(RegisterUser user)
        {
            User dbUser = new User();
            dbUser.FirstName = user.FirstName;
            dbUser.LastName = user.LastName;
            dbUser.PhoneNumber = user.PhoneNumber;
            dbUser.Password = user.CryptPass;
            dbUser.Username = user.Username;

            return dbUser;
        }
开发者ID:vaster,项目名称:Telerik.vasko,代码行数:11,代码来源:ApiToDbModelConverter.cs


示例19: CalculateNextStatLevelPrice

        public static int CalculateNextStatLevelPrice(User user)
        {
            var sum = (user.Agility + user.Charisma + user.Defence + user.Stamina + user.Strength);
            var price = sum * 3;

            if (price < GoldConstants.StartingStatPrice)
            {
                price = GoldConstants.StartingStatPrice;
            }

            return price;
        }
开发者ID:Shkembe-Chorba-Team,项目名称:JustWars,代码行数:12,代码来源:GoldController.cs


示例20: CreateUser

 public User CreateUser(User item)
 {
     var r = this.Core.CreateUser(
         item.UserName,
         item.Password,
         item.GivenName,
         item.MiddleName,
         item.FamilyName,
         item.Email,
         item.Gender,
         item.Birthdate);
     return r;
 }
开发者ID:sergio-gallegos,项目名称:Financiero,代码行数:13,代码来源:Helpers.cs



注:本文中的Models.User类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# variableEvaluator.VariablesEvaluated类代码示例发布时间:2022-05-26
下一篇:
C# Models.Product类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap