当前位置: 首页>>代码示例>>C#>>正文


C# UserRepository.GetById方法代码示例

本文整理汇总了C#中UserRepository.GetById方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.GetById方法的具体用法?C# UserRepository.GetById怎么用?C# UserRepository.GetById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserRepository的用法示例。


在下文中一共展示了UserRepository.GetById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetById_UserDoesNotExist

        public void GetById_UserDoesNotExist()
        {
            var repository = new UserRepository(_contextFactory);

            var retrievedUser = repository.GetById(123);
            Assert.IsNull(retrievedUser);
        }
开发者ID:eugene-blokhin,项目名称:EasyRead,代码行数:7,代码来源:UserRepositoryTest.cs

示例2: Execute

        public override bool Execute(string input)
        {
            if (String.IsNullOrEmpty(input)) return false;

            var repository = new UserRepository();
            int userId;
            if (!Int32.TryParse(input, out userId))
            {
                return false;
            }

            var user = repository.GetById(userId);
            if (user != null)
            {
                repository.Delete(user);
            }
            try
            {
                repository.SaveChanges();
                Success = true;
            }
            catch
            {
                Success = false;
            }
            return Success;
        }
开发者ID:Choulla-Naresh8264,项目名称:WebGridExample,代码行数:27,代码来源:DeleteUserCommand.cs

示例3: CanCreateAlarmTypeAndLog

        public void CanCreateAlarmTypeAndLog()
        {
            IRepository<AlarmType> repoA = new AlarmTypeRepository();
            AlarmType alarm = new AlarmType();
            alarm.NameAlarmType = "PruebaAlarma";
            alarm.Description = "Prueba descriptiva alarma";

            repoA.Save(alarm);

            IRepository<User> repoB = new UserRepository();
            User user = new User();
            user = repoB.GetById(1);
            IRepository<Event> repoC = new EventRepository();
            Event eventt = new Event();
            eventt = repoC.GetById(2);

            IRepository<Log> repoD = new LogRepository();
            Log log = new Log();
            log.DateTime = DateTime.Now;
            log.Text = "Prueba descriptiva log";
            log.Event = eventt;
            log.User = user;

            repoD.Save(log);
        }
开发者ID:diegotrujillor,项目名称:SMCL,代码行数:25,代码来源:UnitTest2.cs

示例4: TestMethod1

        public void TestMethod1()
        {
            IRepository<Monitoring> repoM = new MonitoringRepository();
            var res = repoM.GetByProperty("CommentsOnAlarm", null);

            IRepository<Signal> repo1 = new SignalRepository();
            Signal signal = new Signal();
            signal = repo1.GetById(1);
            IRepository<Appliance> repo2 = new ApplianceRepository();
            Appliance appliance = new Appliance();
            appliance = repo2.GetById(1);
            IRepository<AlarmType> repo3 = new AlarmTypeRepository();
            AlarmType alarmType = new AlarmType();
            alarmType = repo3.GetById(1);
            IRepository<User> repo4 = new UserRepository();
            User user = new User();
            user = repo4.GetById(2);

            IRepository<MappingTag> repoMT = new MappingTagRepository();
            MappingTag tag = new MappingTag();
            tag.Tag = "PruebaTag";
            tag.Description = "Prueba descriptiva mapping tag";
            tag.Signal = signal;
            tag.Appliance = appliance;
            tag.AlarmType = alarmType;

            Monitoring monitor = new Monitoring();
            monitor.Value = float.Parse("2.400");
            monitor.DateTime = DateTime.Now;
            monitor.CommentsOnAlarm = "Prueba de comentarios sobre alarma, monitoreo";
            monitor.MappingTag = tag;
            monitor.User = user;

            tag.Monitorings.Add(monitor);

            repoMT.Save(tag);

            /*INSERT 4000 RECORDS for TEST*/
            //IRepository<Monitoring> repoM = new MonitoringRepository();
            //IRepository<User> repo4 = new UserRepository();
            //User user = new User();
            //user = repo4.GetById(6);

            //IRepository<MappingTag> repoMT = new MappingTagRepository();
            //MappingTag tag = new MappingTag();
            //tag = repoMT.GetById(103);

            //for (int i = 0; i < 4000; i++)
            //{
            //    Monitoring monitor = new Monitoring();
            //    monitor.Value = (1000 + i);
            //    monitor.DateTime = DateTime.Now;
            //    monitor.CommentsOnAlarm = null;
            //    monitor.MappingTag = tag;
            //    monitor.User = user;

            //    repoM.Save(monitor);
            //}
        }
开发者ID:diegotrujillor,项目名称:SMCL,代码行数:59,代码来源:UnitTest5.cs

示例5: GetById_UserExists

        public void GetById_UserExists()
        {
            var repository = new UserRepository(_contextFactory);

            var savedUser = new User { Name = "name", Email = "email" };
            var userId = repository.Create(savedUser);
            var retrievedUser = repository.GetById(userId);

            Assert.IsNotNull(retrievedUser);
            Assert.AreEqual(userId, retrievedUser.Id);
            Assert.AreEqual(savedUser.Name, retrievedUser.Name);
            Assert.AreEqual(savedUser.Email, retrievedUser.Email);
        }
开发者ID:eugene-blokhin,项目名称:EasyRead,代码行数:13,代码来源:UserRepositoryTest.cs

示例6: Save_Entity_Test

        public static void Save_Entity_Test()
        {
            IUserRepository repository = new UserRepository(_session);
            User operador = new User
            {
                Login = "Operador Teste",
                Name = "Operador Teste",
                Password = "Password",
            };

            repository.Insert(operador);

            User operadorBd = repository.GetById(operador.Id);

            Assert.AreEqual(operador.Name, operadorBd.Name);
        }
开发者ID:icarocamelo,项目名称:iLunchWeb,代码行数:16,代码来源:RepositoryTests.cs

示例7: Log

        /// <summary>
        /// Make a new instance for a Log object.
        /// </summary>
        /// <param name="LogMessage"></param>
        /// <param name="EventID"></param>
        /// <param name="UserID"></param>
        /// <returns>A generic object.</returns>
        Object ILoggable.GetNewLog(string LogMessage, int EventID, int UserID)
        {
            var NewLog = new Log();
            IRepository<Event> eventRepo = new EventRepository();
            IRepository<User> eventUser = new UserRepository();

            try
            {
                NewLog.DateTime = DateTime.Now;
                NewLog.Text = LogMessage;
                NewLog.Event = eventRepo.GetById(EventID);
                NewLog.User = eventUser.GetById(UserID);

                return NewLog;
            }
            catch (Exception)
            {
                return null;
            }
        }
开发者ID:diegotrujillor,项目名称:SMCL,代码行数:27,代码来源:LogSMCL.cs

示例8: Get_Entity_By_Id

        public static void Get_Entity_By_Id()
        {
            long id = 0;
            IUserRepository repository = new UserRepository(_session);
            User operadorBd = null;

            User operador = new User
            {
                Login = "Operador Teste Fabrica",
                Name = "Operador Teste Fabrica",
                Password = "Password Fabrica",
            };

            repository.Insert(operador);

            id = operador.Id;

            operadorBd = repository.GetById(id);

            Assert.That(operadorBd.GetHashCode(), Is.Not.EqualTo(operador.GetHashCode()));
            Assert.That(operadorBd.Id, Is.EqualTo(operador.Id));
        }
开发者ID:icarocamelo,项目名称:iLunchWeb,代码行数:22,代码来源:RepositoryTests.cs

示例9: btnSubmit_Click

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            var rep = new UserRepository(new CSBCDbContext());
            User user = rep.GetUser(txtUserName.Text, txtPassword.Text);
            if ((user == null) || (user.UserID == 0))
            {
                lblError.Text = "Invalid user / password";
                lblError.Visible = true;
            }
            else
            {
                Session["UserID"] = user.UserID;
                Session["UserName"] = user.Name;
                Session["UserType"] = user.UserType;
                Session["CompanyID"] = rep.GetById(user.UserID).CompanyID;
                Session["TestMode"] = checkTestMode.Checked;

                var seasonrep = new SeasonRepository(new CSBCDbContext());
                var season = seasonrep.GetCurrentSeason((int)Session["CompanyID"]);
                Session["SeasonID"] = season.SeasonID;
                Response.Redirect("welcome1.aspx");
            }
        }
开发者ID:rsalit,项目名称:CSBC,代码行数:23,代码来源:login.aspx.cs

示例10: GetById_IdIsLessOrEqualToZero

 public void GetById_IdIsLessOrEqualToZero(long id)
 {
     var repository = new UserRepository(_contextFactory);
     repository.GetById(id);
 }
开发者ID:eugene-blokhin,项目名称:EasyRead,代码行数:5,代码来源:UserRepositoryTest.cs

示例11: SetHeader

 protected void SetHeader()
 {
     var rep = new UserRepository(new CSBCDbContext());
     var user = rep.GetById(UserId);
     lblUser1.Text = "Welcome " + user.Name;
     var title = "No Page Selected";
     if (Session["Title"] != null)
     {
         title = Session["Title"].ToString();
     }
     lblTitle.Text = title;
     LoadSeasons();
     ddlSeasons.SelectedValue = SeasonId.ToString();
 }
开发者ID:rsalit,项目名称:CSBC,代码行数:14,代码来源:CSBCAdminMasterPage.master.cs

示例12: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                if (Session["UserID"] == null)
                {
                    Response.Redirect(LoginForm);
                }
                InitializeVariables(new CSBCDbContext());
                SetHeader();
                ddlSeasons.Enabled = true;

            }
            else
            {
                InitializeVariables(new CSBCDbContext());
                if (Session["UserID"] != null)
                {
                    var rep = new UserRepository(new CSBCDbContext());
                    var user = rep.GetById((int)Session["UserID"]);
                }
            }
        }
开发者ID:rsalit,项目名称:CSBC,代码行数:24,代码来源:CSBCAdminMasterPage.master.cs

示例13: ProcessExistingUserRecord

        private HttpResponseMessage ProcessExistingUserRecord(HttpRequestMessage request, UserDTO cqDto, int contactId, string key, int companyId, int userId)
        {
            var ur = new UserRepository();
            //var userRepository = new AppUserRepository();
            var user = new User();
            user = ur.GetById(contactId);
            //int? companyIdx = -1;
            //  is the user eligible to update the prospect?
            bool newfromsetup;
            if (cqDto.CompanyId == null)
            {
                cqDto.CompanyId = companyId.ToString();
                newfromsetup = false;
            }
            else
            {
                newfromsetup = true;
            }

                var validationErrors = GetValidationErrors(ur, user, cqDto, companyId, userId);
                if (validationErrors.Any())
                {
                    return ProcessValidationErrors(request, validationErrors, key);
                }
                //  no validation errors...
                //if (cqDto.Password != "sg")
                //{
                //    user.Password = SecurityUtils.GetBinaryPassword(cqDto.Password.ToString());
                //}
                //else
                //{
                //    SGApp.Models.EF.User userexist = userRepository.GetUser(cqDto.EmailAddress, SecurityUtils.GetBinaryPassword(cqDto.Password), ref companyIdx);
                //    user.Password = userexist.Password;
                //}

                ur.Save(user);
                if (newfromsetup)
                {
                    var rr = new RoleRepository();
                    var roles = rr.GetRoles();
                    foreach (Role role in roles)
                    {
                        var aur = new AppUserRoleRepository();
                        var urole = new UserRole();
                        //ur = aur.GetByUserAndRoleIds(contactId, int.Parse(cqDto.RoleID));
                        urole.UserId = user.UserId;
                        urole.RoleId = role.RoleId;
                        aur.Save(urole);
                    }
                }
                cqDto.Key = key;
                return request.CreateResponse(HttpStatusCode.Accepted, cqDto);
        }
开发者ID:Stimulant-Software,项目名称:HarvestSelect,代码行数:53,代码来源:UserController.cs

示例14: DELRow

 private void DELRow(int id)
 {
     try
     {
         using (var db = new CSBCDbContext())
         {
             var rep = new UserRepository(db);
             var user = new User();
             rep.Delete(rep.GetById(id));
         }
     }
     catch (Exception ex)
     {
         lblError.Text = "DELRow::" + ex.Message;
     }
 }
开发者ID:rsalit,项目名称:CSBC,代码行数:16,代码来源:Users.aspx.cs

示例15: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                if (Session["UserID"] == null)
                {
                    Response.Redirect("Login.aspx");
                }
                InitializeVariables(new CSBCDbContext());

            }
            else
            {
                InitializeVariables(new CSBCDbContext());
                if (Session["UserID"] != null)
                {
                    var rep = new UserRepository(new CSBCDbContext());
                    var user = rep.GetById((int)Session["UserID"]);
                    //lblUserName.Text = "Welcome" + user.Name;
                   // lblTitle.Text = Session["Title"].ToString();
                }

            }
        }
开发者ID:rsalit,项目名称:CSBC,代码行数:25,代码来源:masterpage.master.cs


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