moved update group and update user details procedures to SQLiteProcedures

This commit is contained in:
Watts 2017-04-13 20:58:52 +01:00
parent b8074af57e
commit 64018ef8db
2 changed files with 15 additions and 8 deletions

View File

@ -18,6 +18,14 @@ namespace SQLiteRepository
"select * from " + nameof(UserIdentity) + " order by " + nameof(UserIdentity.LastName) + " collate nocase, " + "select * from " + nameof(UserIdentity) + " order by " + nameof(UserIdentity.LastName) + " collate nocase, " +
nameof(UserIdentity.FirstName) + " collate nocase limit ? offset ?"; nameof(UserIdentity.FirstName) + " collate nocase limit ? offset ?";
public const string GET_ALL_USERS_BY_GROUP =
"select u." + nameof(UserIdentity.Id) + ", u." + nameof(UserIdentity.FirstName) + ", u." +
nameof(UserIdentity.LastName) + ", u." + nameof(UserIdentity.HoursPerWeek) + ", u." +
nameof(UserIdentity.IsContractor) + " from " + nameof(UserIdentity) + " u left join " +
nameof(UserGroupJoinDb) + " ugj on ugj." + nameof(UserGroupJoinDb.UserId_FK) + " = u." +
nameof(UserIdentity.Id) + " where ugj." + nameof(UserGroupJoinDb.GroupId_FK) + "=? order by u." +
nameof(UserIdentity.LastName) + " collate nocase, u." + nameof(UserIdentity.LastName) + " collate nocase";
public const string GET_USER_BY_ID = public const string GET_USER_BY_ID =
"select * from " + nameof(UserIdentity) + " where " + nameof(UserIdentity.Id) + "=?"; "select * from " + nameof(UserIdentity) + " where " + nameof(UserIdentity.Id) + "=?";
@ -38,6 +46,11 @@ namespace SQLiteRepository
"update " + nameof(CardUniqueId) + " set " + nameof(CardUniqueId.LastUsed) + " = ? where " + "update " + nameof(CardUniqueId) + " set " + nameof(CardUniqueId.LastUsed) + " = ? where " +
nameof(CardUniqueId.Id) + " = ?"; nameof(CardUniqueId.Id) + " = ?";
public const string UPDATE_USER_DETAILS =
"update " + nameof(UserIdentity) + " set " + nameof(UserIdentity.FirstName) + "=?, " +
nameof(UserIdentity.LastName) + "=?, " + nameof(UserIdentity.HoursPerWeek) + "=?," +
nameof(UserIdentity.IsContractor) + "=? where " + nameof(UserIdentity.Id) + "=?";
public const string SEARCH_USER_LIST = public const string SEARCH_USER_LIST =
"SELECT * FROM " + nameof(UserIdentity) + " where(" + nameof(UserIdentity.FirstName) + " Like ? OR " + "SELECT * FROM " + nameof(UserIdentity) + " where(" + nameof(UserIdentity.FirstName) + " Like ? OR " +
nameof(UserIdentity.LastName) + " Like ?)"; nameof(UserIdentity.LastName) + " Like ?)";

View File

@ -50,7 +50,7 @@ namespace SQLiteRepository
{ {
users = users =
_connection.Query<UserIdentity>( _connection.Query<UserIdentity>(
"select u.Id, u.FirstName, u.LastName, u.HoursPerWeek, u.IsContractor from UserIdentity u left join UserGroupJoinDb ugj on ugj.UserId_FK = u.Id where ugj.GroupId_FK=?", SQLiteProcedures.GET_ALL_USERS_BY_GROUP,
groupId); groupId);
userCount = users.Count; userCount = users.Count;
} }
@ -311,7 +311,7 @@ namespace SQLiteRepository
{ {
//edit.. //edit..
_connection.Query<UserIdentity>( _connection.Query<UserIdentity>(
"update UserIdentity set FirstName=?, LastName=?, HoursPerWeek=?,IsContractor=? where Id=?", SQLiteProcedures.UPDATE_USER_DETAILS,
user.FirstName, user.FirstName,
user.LastName, user.LastName,
user.HoursPerWeek, user.HoursPerWeek,
@ -460,7 +460,6 @@ namespace SQLiteRepository
} }
else else
{ {
var t = new UserGroupJoinDb();
query = query =
_connection.Query<GroupDb>( _connection.Query<GroupDb>(
"select gdb.GroupId, gdb.GroupName, gdb.AssignedUserCount" + "select gdb.GroupId, gdb.GroupName, gdb.AssignedUserCount" +
@ -501,11 +500,6 @@ namespace SQLiteRepository
public OperationResponse UpdateGroup(Group group) public OperationResponse UpdateGroup(Group group)
{ {
//TODO: I would probably prefer to do this manually.... //TODO: I would probably prefer to do this manually....
var groupDb = new GroupDb
{
GroupId = group.Id,
GroupName = group.Name
};
var resp = _connection.Query<GroupDb>("update GroupDb set GroupName=? where GroupId=?", group.Name, group.Id); var resp = _connection.Query<GroupDb>("update GroupDb set GroupName=? where GroupId=?", group.Name, group.Id);
//var resp = _connection.Update(groupDb); //var resp = _connection.Update(groupDb);
return OperationResponse.UPDATED; return OperationResponse.UPDATED;