public JsonResult IsUserNameExist(string userName) { UsersDBContext DB = new UsersDBContext(); bool isExist = (DB.Users.Any(x => x.Username == userName)); return(Json(!isExist, JsonRequestBehavior.AllowGet)); }
public string UpdateScore([FromBody] System.Text.Json.JsonElement rawQuery) { string rawJson = rawQuery.ToString(); User scoreData = JsonConvert.DeserializeObject <User>(rawJson); error err = new error { Code = 0, Message = "Successfull" }; using (var context = new UsersDBContext()) { User user = context.Users.Where(x => x.Name == scoreData.Name).FirstOrDefault(); if (user == null) { err.Code = 1; err.Message = "Error update values, player doesnt exist"; } else { user.Score += scoreData.Score; user.Win += scoreData.Win; user.Lose += scoreData.Lose; context.SaveChanges(); } } string response = JsonConvert.SerializeObject(err); return(response); }
public UserDAL(IMapper mapper, UsersDBContext context, ICoreRepository coreRepository, IOptions <AppSettings> appSettings) { _appSettings = appSettings.Value ?? throw new ArgumentNullException(nameof(appSettings.Value)); _context = context ?? throw new ArgumentNullException(nameof(context)); _coreRepository = coreRepository ?? throw new ArgumentNullException(nameof(coreRepository)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); }
public OperatorProvider(UsersDBContext dBContext, ILogger <OperatorProvider> logger, IMapper mapper, UserManager <DB.User> userManager, JwtSettings jwtSettings) { this.dBContext = dBContext; this.logger = logger; this.mapper = mapper; this.userManager = userManager; this.jwtSettings = jwtSettings; }
public CustomerProvider(UsersDBContext dBContext, ILogger <CustomerProvider> logger, IMapper mapper, UserManager <DB.User> userManager, JwtSettings jwtSettings) { this.dBContext = dBContext; this.logger = logger; this.mapper = mapper; this.userManager = userManager; this.jwtSettings = jwtSettings; SeedData(); }
public static int AddUserRole(UserRole role) { try { using (var db = new UsersDBContext()) { db.UserRoles.Add(role); return db.SaveChanges(); } } catch (Exception ex) { return -2; } }
public async Task PutUserRequestAsyncTestSuccess() { var options = new DbContextOptionsBuilder <UsersDBContext>() .UseInMemoryDatabase(databaseName: "User") .Options; // Insert seed data into the database using one instance of the context using (var context = new UsersDBContext(options)) { var service = new PutUserService(context); var cancelToken = new CancellationToken(); var response = await service.Handle(new PutUserRequest { Address = "12345", FirstName = "ab", LastName = "cd", DateOfBith = DateTime.Now }, cancelToken).ConfigureAwait(false); Assert.IsNotNull(response); } }
public static int AssignRoleToUser(int UserID, int RoleID) { try { using (var db = new UsersDBContext()) { UsersRolesMapping mapTableObj = new UsersRolesMapping() { UserID = UserID, UserRoleID = RoleID, }; db.UsersRolesMappings.Add(mapTableObj); return db.SaveChanges(); } } catch (Exception ex) { return -2; } }
public async Task PutUserRequestAsyncTestFailure() { var options = new DbContextOptionsBuilder <UsersDBContext>() .UseInMemoryDatabase(databaseName: "User") .Options; // Insert seed data into the database using one instance of the context using (var context = new UsersDBContext(options)) { var service = new PutUserService(context); var cancelToken = new CancellationToken(); try { var response = await service.Handle(new PutUserRequest { Address = "123", FirstName = "", LastName = " ", DateOfBith = DateTime.Now }, cancelToken).ConfigureAwait(false); } catch (ValidationException ex) { Assert.IsTrue(ex.Message.Contains("The FirstName field is required")); } } }
public static int DeleteRole(int id) { try { using (var db = new UsersDBContext()) { UserRole r = db.UserRoles.Single(role => role.UserRoleID == id); if (r != null) { db.UserRoles.Remove(r); return db.SaveChanges(); } else return 0; } } catch (Exception ex) { return -2; } }
public string GetLeader() { List <User> studentsList; LeaderboardData leaderData = new LeaderboardData { Code = 0, Message = "Successfull", Data = null, }; using (var context = new UsersDBContext()) { IQueryable <User> students = from s in context.Users select s; students = students.OrderByDescending(s => s.Score); studentsList = students.ToList(); } leaderData.Data = studentsList; return(JsonConvert.SerializeObject(leaderData)); }
public void BasicAddingUserTest() { var options = new DbContextOptionsBuilder <UsersDBContext>() .UseInMemoryDatabase(databaseName: "User") .Options; // Insert seed data into the database using one instance of the context using (var context = new UsersDBContext(options)) { context.Add(new User() { Address = "12345", DateOfBith = DateTime.Now, FirstName = "Seed", LastName = "Test" }); context.SaveChanges(); } // Use a clean instance of the context to run the test using (var context = new UsersDBContext(options)) { List <User> users = context.Users.Select(s => s).ToList(); Assert.AreEqual(1, users.Count); } }
public void TestDbValidationOfDataModel() { var options = new DbContextOptionsBuilder <UsersDBContext>() .UseInMemoryDatabase(databaseName: "User") .Options; try { // Insert seed data into the database using one instance of the context using (var context = new UsersDBContext(options)) { context.Add(new User() { Address = "12345", DateOfBith = DateTime.Now, FirstName = "", LastName = "Test" }); context.SaveChanges(); } } catch (ValidationException ex) { Assert.IsTrue(ex.Message.Contains("The FirstName field is required")); } }
public async System.Threading.Tasks.Task GetUserIDTestAsync() { var options = new DbContextOptionsBuilder <UsersDBContext>() .UseInMemoryDatabase(databaseName: "User") .Options; // Insert seed data into the database using one instance of the context using (var context = new UsersDBContext(options)) { context.Add(new User() { Address = "142345678910111213141516171819a", DateOfBith = DateTime.Now, FirstName = "Seed", LastName = "Test" }); context.Add(new User() { Address = "142345678910111213141516171819a", DateOfBith = DateTime.Now, FirstName = "Correct", LastName = "Test1234" }); context.Add(new User() { Address = "142345678910111213141516171819a", DateOfBith = DateTime.Now, FirstName = "Seed", LastName = "Test" }); context.SaveChanges(); var Service = new GetUserService(context); var cancelToken = new CancellationToken(); var response = await Service.Handle(new GetUserRequest() { Id = 1 }, cancelToken).ConfigureAwait(false); Assert.IsNotNull(response); Assert.IsTrue(response.Id == 1); } }
public string Post([FromBody] System.Text.Json.JsonElement rawQuery) { string rawJson = rawQuery.ToString(); error err = new error { Code = 0, Message = "Successfull" }; string response; User userData = JsonConvert.DeserializeObject <User>(rawJson); using (var context = new UsersDBContext()) { User user = context.Users.Where(x => x.Name == userData.Name).FirstOrDefault(); if (user != null) { //err.Code = 1; //err.Message = "Name already naken"; //Already have user } else { context.Users.Add(userData); context.SaveChanges(); } } response = JsonConvert.SerializeObject(err); //string jsonData = JsonConvert.SerializeObject(query); //Newtonsoft.Json.Linq.JObject //var aa = JsonConvert.DeserializeObject(value.ToString()); return(response); }
public void BasicFindingCorrectByIdUserTest() { var options = new DbContextOptionsBuilder <UsersDBContext>() .UseInMemoryDatabase(databaseName: "User") .Options; // Insert seed data into the database using one instance of the context using (var context = new UsersDBContext(options)) { context.Add(new User() { Address = "12345", DateOfBith = DateTime.Now, FirstName = "Seed", LastName = "Test" }); context.Add(new User() { Address = "12345", DateOfBith = DateTime.Now, FirstName = "Correct", LastName = "Test1234" }); context.Add(new User() { Address = "12345", DateOfBith = DateTime.Now, FirstName = "Seed", LastName = "Test" }); context.SaveChanges(); } // Use a clean instance of the context to run the test using (var context = new UsersDBContext(options)) { var user = context.Users.FirstOrDefault(s => s.Id == 3); Assert.IsNotNull(user); Assert.IsFalse(string.IsNullOrWhiteSpace(user.FirstName)); Assert.IsFalse(string.IsNullOrWhiteSpace(user.LastName)); Assert.IsFalse(string.IsNullOrWhiteSpace(user.Address)); Assert.IsTrue(user.DateOfBith > DateTime.Now.AddDays(-1)); Assert.IsTrue(user.LastName.Equals("Test1234", StringComparison.InvariantCultureIgnoreCase)); } }
public static List<UserRole> GetAllRoles() { using (var db = new UsersDBContext()) { return (from roles in db.UserRoles select roles).ToList<UserRole>(); } }
public UserRepository(UsersDBContext context) { _context = context; }
public UsersController(UsersDBContext context) { _context = context; }
public static List<User> GetAllUsers() { using (var db = new UsersDBContext()) { return (from users in db.Users select users).ToList<User>(); } }
public UserRepository() { _context = new UsersDBContext(); }
public static int UpdateRole(UserRole UpdatedRole) { using (var db = new UsersDBContext()) { UserRole r = db.UserRoles.Single(role => role.UserRoleID == UpdatedRole.UserRoleID); if (r != null) { r.UserRoleName = UpdatedRole.UserRoleName; r.UserRoleDescription = UpdatedRole.UserRoleDescription; return db.SaveChanges(); } else return 0; } }
public static int RemoveRoleFromUser(int UserID, int RoleID) { try { using (var db = new UsersDBContext()) { if (db.UsersRolesMappings.Any(m => m.UserID == UserID & m.UserRoleID == RoleID)) { UsersRolesMapping mapObj = db.UsersRolesMappings.Single(m => m.UserID == UserID & m.UserRoleID == RoleID); db.UsersRolesMappings.Remove(mapObj); return db.SaveChanges(); } else return 0; } } catch (Exception ex) { return -2; } }
public static List<UserRole> GetRolesOfUser(int UserID) { using (var db = new UsersDBContext()) { //List<int> roleIDs = (from urMap in db.UsersRolesMappings // where urMap.UserID == UserID // select urMap.UserRoleID).ToList<int>(); List<UserRole> listofRoles = (from rmap in db.UsersRolesMappings join usr in db.Users on rmap.UserID equals usr.UserID join rol in db.UserRoles on rmap.UserRoleID equals rol.UserRoleID where usr.UserID == UserID select rol ).ToList<UserRole>(); return listofRoles; } }
public UserService(UsersDBContext context) { _context = context; }
public static int UpdateUser(User UpdatedUser) { using (var db = new UsersDBContext()) { User u = db.Users.Single(user => user.UserID == UpdatedUser.UserID); if (u != null) { u.FirstName = UpdatedUser.FirstName; u.LastName = UpdatedUser.LastName; u.Password = UpdatedUser.Password; u.UserName = UpdatedUser.UserName; u.EmailAddress = UpdatedUser.EmailAddress; return db.SaveChanges(); } else return 0; } }
public static UserRole GetUserRole(int id) { try { using (var db = new UsersDBContext()) { UserRole role = db.UserRoles.Single(r => r.UserRoleID == id); //var u = (from user in db.Users // where user.UserID == UserID // select user); return role; } } catch (Exception ex) { return null; } }
public UserRepository(UsersDBContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); }
public static int DeleteUser(int id) { try { using (var db = new UsersDBContext()) { User u = db.Users.Single(user => user.UserID == id); if (u != null) { db.Users.Remove(u); return db.SaveChanges(); } else return 0; } } catch (Exception ex) { return -2; } }
public DaliyLogsController(UsersDBContext context) { _context = context; }
public GetUserService(UsersDBContext dBContext) { DatabaseConnection = dBContext; }
public static User GetUserByID(int UserID) { try { using (var db = new UsersDBContext()) { User u = db.Users.Single(user => user.UserID == UserID); //var u = (from user in db.Users // where user.UserID == UserID // select user); return u; } } catch (Exception ex) { return null; } }
public UsersRepository(UsersDBContext usersDBContext) { this.usersDBContext = usersDBContext; }
public static User GetUserByUserName(string UserName) { try { using (var db = new UsersDBContext()) { var u = (from user in db.Users where user.UserName == UserName select user); return (User)u; } } catch (Exception ex) { return null; } }