Пример #1
0
        public JsonResult IsUserNameExist(string userName)
        {
            UsersDBContext DB      = new UsersDBContext();
            bool           isExist = (DB.Users.Any(x => x.Username == userName));

            return(Json(!isExist, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        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);
        }
Пример #3
0
 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));
 }
Пример #4
0
 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;
 }
Пример #5
0
 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();
 }
Пример #6
0
 public static int AddUserRole(UserRole role)
 {
     try
     {
         using (var db = new UsersDBContext())
         {
             db.UserRoles.Add(role);
             return db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         return -2;
     }
 }
Пример #7
0
        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);
            }
        }
Пример #8
0
 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;
     }
 }
Пример #9
0
        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"));
                }
            }
        }
Пример #10
0
 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;
     }
 }
Пример #11
0
        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));
        }
Пример #12
0
        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);
            }
        }
Пример #13
0
        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"));
            }
        }
Пример #14
0
        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);
            }
        }
Пример #15
0
        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);
        }
Пример #16
0
        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));
            }
        }
Пример #17
0
 public static List<UserRole> GetAllRoles()
 {
     using (var db = new UsersDBContext())
     {
         return (from roles in db.UserRoles
                 select roles).ToList<UserRole>();
     }
 }
Пример #18
0
 public UserRepository(UsersDBContext context)
 {
     _context = context;
 }
Пример #19
0
 public UsersController(UsersDBContext context)
 {
     _context = context;
 }
Пример #20
0
 public static List<User> GetAllUsers()
 {
     using (var db = new UsersDBContext())
     {
         return (from users in db.Users
                 select users).ToList<User>();
     }
 }
Пример #21
0
 public UserRepository()
 {
     _context = new UsersDBContext();
 }
Пример #22
0
 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;
     }
 }
Пример #23
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;
     }
 }
Пример #24
0
        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;
            }
        }
Пример #25
0
 public UserService(UsersDBContext context)
 {
     _context = context;
 }
Пример #26
0
 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;
     }
 }
Пример #27
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));
 }
Пример #29
0
 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;
     }
 }
Пример #30
0
 public DaliyLogsController(UsersDBContext context)
 {
     _context = context;
 }
Пример #31
0
 public GetUserService(UsersDBContext dBContext)
 {
     DatabaseConnection = dBContext;
 }
Пример #32
0
 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;
     }
 }
Пример #33
0
 public UsersRepository(UsersDBContext usersDBContext)
 {
     this.usersDBContext = usersDBContext;
 }
Пример #34
0
 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;
     }
 }