public int CountActivGames(int acceptUserId, int requestUserId) { string q = $"select Count(Id) from Games g where (g.RequestUser={requestUserId} and g.AcceptUser={acceptUserId} and g.Status <> 'Close') or (g.RequestUser={acceptUserId} and g.AcceptUser={requestUserId}) and g.Status <> 'Close'"; using (CommanderBase commander = DBContext.CreateCommander()) { var obj = commander.Scaller(q); return(obj != null?Convert.ToInt32(obj) : default(int)); } }
public bool AddRole(int userId, int roleId) { string q = $"INSERT INTO UserRole (AppUserId , RoleId) VALUES({userId} , {roleId} )"; using (CommanderBase commander = DBContext.CreateCommander()) { var ur = commander.NonQuery(q); return(ur); } }
public static IDictionary <string, object> UseContext(this CommanderBase commander, bool useGlobalContext = false) { // Check for commander specific context if (!commander.HasContext()) { Context.Add(commander, new Dictionary <string, object>()); } return((useGlobalContext) ? Context[null] : Context[commander]); }
public bool DeleteRole(int userId, int roleId) { string q = $"DELETE FROM UserRole WHERE AppUserId={userId} and RoleId={roleId}"; using (CommanderBase commander = DBContext.CreateCommander()) { var ur = commander.NonQuery(q); return(ur); } }
public List <UIUserRoles> GetUserRoles(int id) { string q = $"select * from UserRole u join Role r on u.RoleId=r.Id Where u.AppUserId={id}"; using (CommanderBase commander = DBContext.CreateCommander()) { var ur = commander.Reader <UIUserRoles>(q); return(ur); } }
public List <UIGames> GetUserGames(int id) { string q = $"select g.*, " + $"u.UserName as AcceptUserName, " + $"u1.UserName as RequestUserName " + $"from Games g " + $"LEFT JOIN AppUser u on u.Id = g.AcceptUser " + $"LEFT JOIN AppUser u1 on u1.Id = g.RequestUser " + $"where g.RequestUser = {id} or g.AcceptUser = {id}"; using (CommanderBase commander = DBContext.CreateCommander()) return(commander.Reader <UIGames>(q)); }
public List <UISubCategory> GetUISubCategories(int id = 0) { string query = "SELECT s.Id, s.Name, s.CategoryId, " + "s.Description, c.Name as CategoryName " + "FROM SubCategory s LEFT JOIN Category c ON s.CategoryId = c.ID"; using (CommanderBase commander = DBContext.CreateCommander()) { if (id > 0) { return(commander.Reader <UISubCategory>(query + " WHERE s.Id=" + id)); } return(commander.Reader <UISubCategory>(query)); } }
public bool IsUserRole(int userId, int roleId) { string q = $"select * from UserRole u Where u.AppUserId={userId} and u.RoleId={roleId}"; using (CommanderBase commander = DBContext.CreateCommander()) { var ur = commander.Reader <UserRole>(q); if (ur.Count > 0) { return(true); } else { return(false); } } }
public int GetIdByColumName(string columName, object value) { string q = $"Select u.Id from AppUser u Where u.{columName} = @{columName}"; using (CommanderBase commander = DBContext.CreateCommander()) { var obj = commander.Scaller(q, new List <System.Data.Common.DbParameter>() { commander.SetParametr(columName, value) }); if (obj != null) { return(Convert.ToInt32(obj)); } else { return(default(int)); } } }
public static void Main(string[] args) { ProcessArgs(args); admin = new Admin(); Task <bool> t = Task.Run(() => admin.Launch()); t.Wait(); if (t.Result == true) { if (infile != null) { commander = new FileCommander(infile); } else { commander = new ReadExecPrint(); commander.Responses.Subscribe( (line) => Console.WriteLine($"data: {line}"), () => Console.WriteLine("Sequence Completed.") ); } try { Task.Run(() => commander.Run(admin)).Wait(); } catch (Exception e) { Console.WriteLine(e.Message); if (e.InnerException != null) { Console.WriteLine(e.InnerException.Message); } } } else { Console.WriteLine("bad admin"); } }
public static bool HasContext(this CommanderBase commander) { return(Context.ContainsKey(commander)); }