public Task <TRole> FindByIdAsync(string roleId) { using (var connection = DbConnectionFactory.NewDbConnection()) { return(Task.FromResult <TRole>(connection.Query <TRole>(FileHandler.ReadFileContent("UserRole.FindById.sql"), roleId).SingleOrDefault())); } }
public Task SetEmailConfirmedAsync(TUser user, bool confirmed) { using (var connection = DbConnectionFactory.NewDbConnection()) { connection.Execute(FileHandler.ReadFileContent("User.UpdateEmailConfirmedById.sql"), user); } return(Task.FromResult(0)); }
public virtual Task <IList <UserLoginInfo> > GetLoginsAsync(TUser user) { if (user == null) { throw new ArgumentNullException("user"); } using (var connection = DbConnectionFactory.NewDbConnection()) { return(Task.FromResult((IList <UserLoginInfo>)connection.Query <UserLoginInfo>(FileHandler.ReadFileContent("UserLogin.FindById.sql"), new { user.Id }).ToList())); } }
public Task <TUser> FindByEmailAsync(string email) { if (String.IsNullOrEmpty(email)) { throw new ArgumentNullException("email"); } using (var connection = DbConnectionFactory.NewDbConnection()) { return(Task.FromResult(connection.Query <TUser>(FileHandler.ReadFileContent("User.FindByEmail.sql"), new { email }).SingleOrDefault())); } }
public Task <TRole> FindByNameAsync(string roleName) { if (String.IsNullOrWhiteSpace(roleName)) { throw new ArgumentNullException("roleName"); } using (var connection = DbConnectionFactory.NewDbConnection()) { return(Task.FromResult <TRole>(connection.Query <TRole>(FileHandler.ReadFileContent("UserRole.FindByName.sql"), new { Name = roleName }).SingleOrDefault())); } }
public virtual Task <TUser> FindAsync(UserLoginInfo login) { if (login == null) { throw new ArgumentNullException("login"); } using (var connection = DbConnectionFactory.NewDbConnection()) { return(Task.FromResult(connection.Query <TUser>(FileHandler.ReadFileContent("User.FindByProviderAndKey.sql"), login).SingleOrDefault())); } }
public IHttpActionResult ListCoursesByDepartmentYearSeason( string departmentName, int year, int season) { using (var connection = DbConnectionFactory.NewDbConnection()) { IEnumerable <Course> courses = connection.Query <Course>( FileHandler.ReadFileContent("Registration.ListCoursesByDepartmentYearSeason.sql"), new { departmentName, year, season }); return(Ok(courses)); } }
public virtual Task UpdateAsync(TUser user) { if (user == null) { throw new ArgumentNullException("user"); } using (var connection = DbConnectionFactory.NewDbConnection()) { connection.Execute(FileHandler.ReadFileContent("User.Update.sql"), user); return(Task.FromResult(0)); } }
public virtual Task <TUser> FindByNameAsync(string userName) { if (string.IsNullOrWhiteSpace(userName)) { throw new ArgumentNullException("userName"); } using (var connection = DbConnectionFactory.NewDbConnection()) { var result = connection.Query <TUser>(FileHandler.ReadFileContent("User.FindByName.sql"), new { userName }).SingleOrDefault(); return(Task.FromResult <TUser>(result)); } }
public Task SetEmailAsync(TUser user, string email) { if (user == null) { throw new ArgumentNullException("user"); } using (var connection = DbConnectionFactory.NewDbConnection()) { connection.Execute(FileHandler.ReadFileContent("User.UpdateEmailById.sql"), user); } return(Task.FromResult(0)); }
public IHttpActionResult CoursesByStudent(string studentId) { // pass userId to the query so as to provide only to the self // (security check - parameter tempering) var userId = RequestContext.Principal.Identity.GetUserId(); using (var connection = DbConnectionFactory.NewDbConnection()) { IEnumerable <Course> courses = connection.Query <Course>( FileHandler.ReadFileContent("Registration.CoursesByStudent.sql"), new { studentId = studentId, userId = userId }); return(Ok(courses)); } }
public virtual Task <TUser> FindByIdAsync(string id) { if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException("id"); } Guid parsedUserId; if (!Guid.TryParse(id, out parsedUserId)) { throw new ArgumentOutOfRangeException("id", string.Format("'{0}' is not a valid GUID.", new { id })); } using (var connection = DbConnectionFactory.NewDbConnection()) { return(Task.FromResult(connection.Query <TUser>(FileHandler.ReadFileContent("User.FindById.sql"), new { id = parsedUserId.ToString() }).SingleOrDefault())); } }
public virtual Task RemoveLoginAsync(TUser user, UserLoginInfo login) { if (user == null) { throw new ArgumentNullException("user"); } if (login == null) { throw new ArgumentNullException("login"); } using (var connection = DbConnectionFactory.NewDbConnection()) { connection.Execute(FileHandler.ReadFileContent("UserLogin.RemoveLoginByProviderAndKey.sql"), new { userId = user.Id, login.LoginProvider, login.ProviderKey }); } return(Task.FromResult(0)); }
public IHttpActionResult AddCourseForStudent([FromBody] NewCourseRequestDto ncr) { // TODO: gseng - add parameter tempering guard here. using (var connection = DbConnectionFactory.NewDbConnection()) { var affectedRows = connection.Execute( FileHandler.ReadFileContent("Registration.AddCourseForStudent.sql"), new { studentId = ncr.StudentId, courseId = ncr.CourseId }); if (affectedRows > 0) { return(Ok()); } else { return(InternalServerError()); } } }
public Task <IList <string> > GetRolesAsync(TUser user) { if (user == null) { throw new ArgumentNullException("user"); } List <string> roles = null; using (var connection = DbConnectionFactory.NewDbConnection()) { roles = connection.Query <string>(FileHandler.ReadFileContent("Roles.GetAllRoleNamesByUserId.sql"), new { Id = user.Id }).ToList(); } if (roles != null) { return(Task.FromResult <IList <string> >(roles)); } return(Task.FromResult <IList <string> >(null)); }