當前位置: 首頁>>代碼示例>>C#>>正文


C# Models.User類代碼示例

本文整理匯總了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);
        }
開發者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


注:本文中的Models.User類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。