本文整理汇总了C#中UserRepository.GetByID方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.GetByID方法的具体用法?C# UserRepository.GetByID怎么用?C# UserRepository.GetByID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.GetByID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangeStatus
public string ChangeStatus()
{
string result = "";
try
{
int id = 0;
int.TryParse(Request["id"], out id);
byte status = 0;
byte.TryParse(Request["status"], out status);
var repo = new UserRepository();
var v = repo.GetByID(id);
if (v != null)
{
v.RecordStatus = status;
repo.SaveChanges();
}
result = JsonResult(true, Resources.Messages.StatusChanged);
}
catch (Exception ex)
{
result = JsonResult(false, ex.Message);
}
return result;
}
示例2: Edit
public ActionResult Edit(int? id)
{
User user;
UserRepository userRep = new UserRepository();
if (!id.HasValue)
{
user = new User();
}
else
{
user = userRep.GetByID(id.Value);
if (user == null)
{
return RedirectToAction("List");
}
}
UsersEditVM model = new UsersEditVM();
model.ID = user.ID;
model.Username = user.Username;
model.FirstName = user.FirstName;
model.LastName = user.LastName;
model.Email = user.Email;
model.Groups = PopulateAssignedGroups(user);
return View(model);
}
示例3: AddSubject
public ActionResult AddSubject(int? id)
{
TeacherAddSubjectVM model = new TeacherAddSubjectVM();
CourseRepository cRepo = new CourseRepository();
UserRepository<Teacher> teacherRepo = new UserRepository<Teacher>();
List<SelectListItem> list = new List<SelectListItem>();
Teacher teacher = teacherRepo.GetByID(id.Value);
model.Title = teacher.Title.Name;
model.FirstName = teacher.FirstName;
model.LastName = teacher.LastName;
model.TeacherID = teacher.ID;
var courses = cRepo.GetAll();
foreach (var item in courses)
{
list.Add(new SelectListItem() { Text = item.Name, Value = item.ID.ToString() });
}
model.CoursesList = list;
return View(model);
}
示例4: ChangePassword
public ActionResult ChangePassword(StudentChangePasswordVM model)
{
if (!ModelState.IsValid)
{
return View();
}
if (model.NewPassword != model.NewPasswordRepeat)
{
ModelState.AddModelError("Error", "New password dont match");
return View(model);
}
UserRepository<Student> stuRepo = new UserRepository<Student>();
Student student = stuRepo.GetByID(model.StudentID);
Passphrase hash = PasswordHasher.Hash(model.OldPassword);
if (PasswordHasher.Equals(model.OldPassword, student.Salt, student.Hash))
{
Passphrase hash2 = PasswordHasher.Hash(model.NewPassword);
student.Salt = hash2.Salt;
student.Hash = hash2.Hash;
stuRepo.Save(student);
}
else
{
ModelState.AddModelError("Error", "Old password dont match");
return View(model);
}
return RedirectToAction("Index", "Student");
}
示例5: AddReference
public ActionResult AddReference(int counterId, int userId)
{
using (var db = new GazDbContext())
{
var userrepo = new UserRepository(db);
var counterrepo = new CountersRepository(db);
var user = userrepo.GetByID(userId);
var counter = counterrepo.GetByID(counterId);
user.User_Counters.Add(counter);
userrepo.Commit();
return Content("Ref added");
}
}
示例6: TestGetById
public void TestGetById()
{
try
{
const string id = "567ba8c0270421f254fd4066";
var userRepo = new UserRepository();
var task = userRepo.GetByID(id);
task.Wait();
Assert.IsNotNull(task.Result);
Assert.IsNotNull(task.Result.Emails);
Assert.IsTrue(id.Equals(task.Result.Id));
}
catch (Exception e)
{
Assert.Fail(e.Message);
}
}
示例7: Metric
public async Task<dynamic> Metric([FromBody] JToken jsonbody)
{
var userId = string.Empty;
IEnumerable<string> values;
if (Request.Headers.TryGetValues("x-user-id", out values))
userId = values.FirstOrDefault();
if (string.IsNullOrWhiteSpace(userId))
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "x-user-id not found."));
if (jsonbody == null)
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid data."));
var userRepo = new UserRepository();
var userEntity = await userRepo.GetByID(userId);
if (userEntity == null)
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Format("user {0} not found.", userId)));
switch (jsonbody.Type)
{
case JTokenType.Object:
if (!CheckIfContainUserId(jsonbody))
jsonbody["userid"] = userId;
await LambdaEventHubs.SendMessage(jsonbody.ToString());
break;
case JTokenType.Array:
var jAarray = jsonbody.ToList();
foreach (var jToken in jAarray)
{
if (!CheckIfContainUserId(jToken))
jToken["userid"] = userId;
}
await LambdaEventHubs.SendMessage(jAarray.Select(j => j.ToString()));
break;
default:
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid data."));
}
return new { result = "OK" };
}
示例8: ChangePassword
public async Task<dynamic> ChangePassword([FromBody] JToken jsonbody)
{
if (jsonbody == null || jsonbody.Type != JTokenType.Object)
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid data."));
//check data
var userId = jsonbody.SelectToken("id");
if (userId == null || string.IsNullOrWhiteSpace(userId.ToString()))
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "id is missed."));
var newPassword = jsonbody.SelectToken("newpassword");
if (newPassword == null || string.IsNullOrWhiteSpace(newPassword.ToString()))
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "new password is missed."));
var userRepo = new UserRepository();
var userEntity = await userRepo.GetByID(userId.ToString());
if(userEntity == null)
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid id."));
userEntity.Password = Encryptor.GetInstance().Encrypt(newPassword.ToString());
userRepo.Update(userEntity);
return Ok();
}
示例9: Save
public string Save()
{
string result = "";
try
{
var repo = new UserRepository();
var userInput = JsonConvert.DeserializeObject<DAL.User>(Request["user"]);
if (userInput != null)
{
if (repo.IsExist(userInput.ID, userInput.UserName))
return JsonResult(false, "1");
else
{
if (userInput.ID == 0)
repo.Add(userInput);
else
{
var user = repo.GetByID(userInput.ID);
if (user != null)
{
user.UserName = userInput.UserName;
user.RoleID = userInput.RoleID;
user.RoleName = userInput.RoleName;
if (userInput.Password + "" != "")
user.Password = userInput.Password;
repo.SaveChanges();
}
}
result = JsonResult(true, Resources.Messages.Save);
}
}
else
result = JsonResult(true, Resources.Messages.Save);
}
catch (Exception ex)
{
result = JsonResult(false, ex.Message);
}
return result;
}
示例10: UpdateUserProfile
public async Task<dynamic> UpdateUserProfile([FromBody] JToken jsonbody)
{
if (jsonbody == null || jsonbody.Type != JTokenType.Object)
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid data."));
var userId = jsonbody.SelectToken("id");
if (userId == null || string.IsNullOrWhiteSpace(userId.ToString()))
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Id is missed."));
//check if user exists or not
var userRepo = new UserRepository();
var userEntity = await userRepo.GetByID(userId.ToString());
if (userEntity == null)
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "User does not exist."));
//save to db
var displayName = jsonbody.SelectToken("displayname");
if (displayName != null)
{
userEntity.DisplayName = displayName.ToString();
}
var options = (JObject)jsonbody.SelectToken("options");
if (options != null)
{
if(userEntity.Options == null)
userEntity.Options = new Dictionary<string, string>();
foreach (var jProperty in options.Properties())
{
if (userEntity.Options.ContainsKey(jProperty.Name))
{
userEntity.Options.Remove(jProperty.Name);
}
userEntity.Options.Add(jProperty.Name, jProperty.Value.ToString());
}
}
userRepo.Update(userEntity);
return Ok();
}
示例11: Index
public ActionResult Index()
{
StudentIndexVM model = new StudentIndexVM();
UserRepository<Student> stuRepo = new UserRepository<Student>();
CourseRepository courseRepo = new CourseRepository();
GradeRepository gradeRepo = new GradeRepository();
UserRepository<Teacher> teacherRepo = new UserRepository<Teacher>();
Student student = stuRepo.GetByID(Models.AuthenticationManager.LoggedUser.ID);
model.FacultiNumber = student.FacultiNumber;
model.FirstName = student.FirstName;
model.LastName = student.LastName;
Course course = courseRepo.GetAll(filter: x => x.CourseSubject.Any(c => c.Course.Student.Any(s => s.ID == Models.AuthenticationManager.LoggedUser.ID))).FirstOrDefault();
model.CourseName = course.Name;
model.Grades = gradeRepo.GetAll(filter: g => g.StudentID == Models.AuthenticationManager.LoggedUser.ID);
return View(model);
}
示例12: ExportSubjectListToExcel
public void ExportSubjectListToExcel(int id)
{
StudentIndexVM model = new StudentIndexVM();
GradeRepository gradeRepo = new GradeRepository();
UserRepository<Student> studentRepo = new UserRepository<Student>();
Student student = studentRepo.GetByID(id);
model.Grades = gradeRepo.GetAll(filter: s => s.StudentID == id);
var grid = new System.Web.UI.WebControls.GridView();
var products = new System.Data.DataTable(student.FirstName);
products.Columns.Add("Subject", typeof(string));
products.Columns.Add("Grade", typeof(string));
foreach (var item in model.Grades)
{
products.Rows.Add(item.Subject.Name, item.GradeValue);
}
grid.DataSource = products;
grid.DataBind();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + student.FacultiNumber + ".xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
示例13: EditTeacher
public ActionResult EditTeacher(TeacherEditTeacherVM model)
{
if (!ModelState.IsValid)
{
model.TitleList = TeacherTitle();
return View(model);
}
UnitOfWork unitOfWork = new UnitOfWork();
UserRepository<Teacher> teacherRepo = new UserRepository<Teacher>(unitOfWork);
TitleRepository tiRepo = new TitleRepository(unitOfWork);
Teacher teacher = teacherRepo.GetByID(model.TeacherID);
try
{
int TitleId = Convert.ToInt32(model.selectedValueID);
Title title = tiRepo.GetByID(TitleId);
if (model.FirstName != teacher.FirstName || model.LastName != teacher.LastName || model.Active != teacher.Active || TitleId != teacher.Title.ID)
{
teacher.FirstName = model.FirstName;
teacher.LastName = model.LastName;
teacher.Username = model.FirstName;
teacher.Active = model.Active;
teacher.Title = title;
teacherRepo.Save(teacher);
unitOfWork.Commit();
}
}
catch (Exception)
{
unitOfWork.RollBack();
}
return RedirectToAction("ListTeachers", "Teacher");
}
示例14: TestUpdate
public void TestUpdate()
{
try
{
const string pattern = "567ba8c0270421f254fd4066";
var userRepo = new UserRepository();
var task = userRepo.GetByID(pattern);
task.Wait();
Assert.IsNotNull(task.Result);
var user = task.Result;
var status = user.Status == UserStatus.Created ? UserStatus.Confirmed : UserStatus.Created;
var updateTask = userRepo.UpdateStatus(pattern, status);
updateTask.Wait();
Assert.IsTrue(updateTask.Result > 0);
}
catch (Exception e)
{
Assert.Fail(e.Message);
}
}
示例15: EditStudent
public ActionResult EditStudent(StudentEditStudentVM model)
{
CourseRepository courseRepo = new CourseRepository();
if (!ModelState.IsValid)
{
List<SelectListItem> list = new List<SelectListItem>();
var courses = courseRepo.GetAll();
foreach (var item in courses)
{
list.Add(new SelectListItem() { Text = item.Name + " || " + item.FKNumber, Value = item.ID.ToString() });
}
model.CoursesList = list;
return View(model);
}
UserRepository<Student> stuRepo = new UserRepository<Student>();
Student student = new Student();
Course course = new Course();
student = stuRepo.GetByID(model.StudentID);
int courseID = Convert.ToInt32(model.selectedValueID);
if (model.CourseID != courseID)
{
course = courseRepo.GetAll(filter: c => c.ID == courseID).FirstOrDefault();
var fkNumberCount = (from t in stuRepo.GetAll(filter: x => x.FacultiNumber.Contains(course.FKNumber)).OrderByDescending(s => s.FacultiNumber)
select t).FirstOrDefault();
if (fkNumberCount == null)
{
student.FacultiNumber = (Convert.ToInt32(course.FKNumber) * 1000 + 1).ToString();
}
else
{
student.FacultiNumber = (Convert.ToInt32(fkNumberCount.FacultiNumber) + 1).ToString();
}
student.CourseID = courseID;
}
student.FirstName = model.FirstName;
student.Username = "stu" + student.FacultiNumber;
student.LastName = model.LastName;
student.Active = model.Active;
stuRepo.Save(student);
return RedirectToAction("ListStudents", "Student");
}