本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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);
//}
}
示例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);
}
示例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);
}
示例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;
}
}
示例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));
}
示例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");
}
}
示例10: GetById_IdIsLessOrEqualToZero
public void GetById_IdIsLessOrEqualToZero(long id)
{
var repository = new UserRepository(_contextFactory);
repository.GetById(id);
}
示例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();
}
示例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"]);
}
}
}
示例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);
}
示例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;
}
}
示例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();
}
}
}