Esempio n. 1
0
 public Task Update(
     Candidato nuevaInformacionCandidato
     )
 {
     nuevaInformacionCandidato.FechaDeActualizacion = DateTime.Now;
     return(repository.Save(nuevaInformacionCandidato));
 }
Esempio n. 2
0
        private void GenericDicItemTest <T>() where T : GenericDictionaryItem, new()
        {
            var random = new Random((int)DateTime.Now.Ticks);

            var newItem = new T
            {
                DateStart = GetRandomDateTime(random),

                DateEnd = GetRandomDateTime(random),

                Name         = GenerateRandomString(8),
                PublicCode   = GenerateRandomString(8),
                ResourceName = GenerateRandomString(8)
            };

            var repository = new CrudRepository <T>(_uow);

            repository.Save(newItem);

            var savedItem = repository.GetById(newItem.Id);

            Assert.NotNull(savedItem);
            Assert.AreEqual(newItem.DateStart, savedItem.DateStart);
            Assert.AreEqual(newItem.DateEnd, savedItem.DateEnd);
            Assert.AreEqual(newItem.Name, savedItem.Name);
            Assert.AreEqual(newItem.PublicCode, savedItem.PublicCode);
            Assert.AreEqual(newItem.ResourceName, savedItem.ResourceName);
        }
Esempio n. 3
0
        public async Task <Dto.ApiResponse <Dto.Role> > CreateRole(Dto.Role model)
        {
            var response = new Dto.ApiResponse <Dto.Role>();

            if (string.IsNullOrWhiteSpace(model.Name) || model.BusinessId == 0)
            {
                response.Success = false;
                response.ErrorMesssage.Add(MtsResource.InvalidRoleBusiness);
            }

            var isRoleExist = _roleRepo.List(i => i.Name == model.Name && i.BusinessId == model.BusinessId).Any();

            if (isRoleExist)
            {
                response.Success = false;
                response.ErrorMesssage.Add(MtsResource.RoleAlreadyExist);
            }

            if (response.Success)
            {
                var roleEntity = _mapper.Map <Entity.Role>(model);
                await _roleRepo.Save(roleEntity);

                response.DataResponse        = _mapper.Map <Dto.Role>(roleEntity);
                response.DataResponse.UserId = model.UserId;
            }

            return(response);
        }
Esempio n. 4
0
        public async Task <ApiResponse <User> > RegisterUser(User user)
        {
            var response   = new ApiResponse <User>();
            var userEntity = _mapper.Map <Entity.User>(user);

            userEntity.IsActive = true;

            var businessEntity = _mapper.Map <Entity.Business>(user.Business);

            var isEmailExist = _userRepo.List(i => i.Email == user.Email).Any();

            if (isEmailExist)
            {
                response.Success = false;
                response.ErrorMesssage.Add(MtsResource.InvalidEmail);
            }

            var isBusinessNameExist = _businessRepo.List(i => i.Name == user.Business.Name).Any();

            if (isBusinessNameExist)
            {
                response.Success = false;
                response.ErrorMesssage.Add(MtsResource.InvalidBusinessName);
            }

            if (response.Success)
            {
                using (var tx = _registrationRequestRepo.Context.Database.BeginTransaction())
                {
                    try
                    {
                        userEntity.Password = _crypto.CalculateHash(user.Password);
                        await _userRepo.Save(userEntity);

                        await _businessRepo.Save(businessEntity);

                        await _userBusinessRepo.Save(new Entity.UserBusiness
                        {
                            BusinessId = businessEntity.Id,
                            UserId     = userEntity.Id
                        });

                        user                  = _mapper.Map <User>(userEntity);
                        user.Business         = _mapper.Map <Business>(businessEntity);
                        response.DataResponse = user;

                        tx.Commit();
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.ErrorMesssage.Add(e.GetBaseException().Message);
                        tx.Rollback();
                    }
                }
            }


            return(response);
        }
Esempio n. 5
0
        public async Task <ApiResponse <string> > RequestRegistration(string email)
        {
            var response = new ApiResponse <string>();

            using (var tx = _registrationRequestRepo.Context.Database.BeginTransaction())
            {
                try
                {
                    var isEmailAlreadyRegistered = _userRepo.List(i => i.Email == email).Any();
                    if (isEmailAlreadyRegistered)
                    {
                        response.Success = false;
                        response.ErrorMesssage.Add(MtsResource.InvalidEmail);
                    }
                    if (response.Success)
                    {
                        var    registrationRequest = _registrationRequestRepo.List(i => i.Email == email).FirstOrDefault();
                        string token = RandomGenerator.GenerateString(50);

                        if (registrationRequest != null)
                        {
                            registrationRequest.Token = token;
                            await _registrationRequestRepo.Update(registrationRequest);
                        }
                        else
                        {
                            await _registrationRequestRepo.Save(new Entity.RegistrationRequest
                            {
                                Email       = email,
                                Token       = token,
                                CreatedDate = DateTime.UtcNow,
                                UpdatedDate = DateTime.UtcNow
                            });
                        }

                        _emailService.Send(new EmailBody
                        {
                            Content = GenerateRegistrationRequestBody(token, email),
                            From    = "*****@*****.**",
                            To      = email,
                            Subject = "Registration Request"
                        });

                        tx.Commit();
                    }
                }
                catch (Exception e)
                {
                    response.Success = false;
                    response.ErrorMesssage.Add(e.GetBaseException().Message);
                    tx.Rollback();
                }
            }

            return(response);
        }
        /// <summary>
        /// Regresa el Id del usuario insertado
        /// </summary>
        /// <param name="id"></param>
        /// <param name="nombre"></param>
        /// <param name="contraseña"></param>
        /// <param name="activo"></param>
        /// <returns></returns>
        public async Task <int> Save(
            int?id,
            string nombre,
            string contraseña,
            bool?activo
            )
        {
            var usuario = await repository.FindById(id) ?? new Usuario();

            usuario.Nombre = nombre;
            if (!string.IsNullOrEmpty(contraseña))
            {
                usuario.Contraseña = HashPassword(contraseña);
            }
            usuario.Activo = activo ?? throw new ValidationErrorException(nameof(Usuario.Activo), ValidationErrorType.Required);

            await repository.Save(usuario);

            return(usuario.Id);
        }
Esempio n. 7
0
 public static void InsertBusiness()
 {
     using (var tx = entities.Database.BeginTransaction())
     {
         repo.Save(new Business
         {
             CreatedDate      = DateTime.UtcNow,
             UpdatedDate      = DateTime.UtcNow,
             NatureOfBusiness = "test",
             Name             = "Test",
             Website          = "website"
         }).Wait();
     }
 }
Esempio n. 8
0
        public async Task <Dto.ApiResponse <object> > AssignRoleApplicationFeatureForUser(Dto.RoleApplicationFeature model)
        {
            var response              = new Dto.ApiResponse <object>();
            var roleAppEntity         = _mapper.Map <Entity.RoleApplicationFeature>(model);
            var isRoleAlreadyAssigned = _roleAppRepo.List(i => i.RoleId == model.RoleId && i.ApplicationFeatureId == model.ApplicationFeatureId).Any();

            if (isRoleAlreadyAssigned)
            {
                response.Success = false;
                response.ErrorMesssage.Add(MtsResource.RoleAlreadyAssignToFeature);
            }

            if (response.Success)
            {
                await _roleAppRepo.Save(roleAppEntity);
            }
            return(response);
        }
Esempio n. 9
0
        public void UserTest()
        {
            var newItem = new IdentityUser
            {
                Username       = GenerateRandomString(20),
                Email          = GenerateRandomString(20),
                HashedPassword = GenerateRandomString(20)
            };

            var repository = new CrudRepository <IdentityUser>(_uow);

            repository.Save(newItem);

            var savedItem = repository.GetById(newItem.Id);

            Assert.NotNull(savedItem);
            Assert.AreEqual(newItem.Email, savedItem.Email);
            Assert.AreEqual(newItem.Username, savedItem.Username);
            Assert.AreEqual(newItem.HashedPassword, savedItem.HashedPassword);
        }
Esempio n. 10
0
        public void PlayerUserTest()
        {
            var random = new Random((int)DateTime.Now.Ticks);

            var newItem = new PlayerUser
            {
                EugenUserId = random.Next(1000000, 10000000),
                Name        = GenerateRandomString(20)
            };

            var repository = new CrudRepository <PlayerUser>(_uow);

            repository.Save(newItem);

            var savedItem = repository.GetById(newItem.Id);

            Assert.NotNull(savedItem);
            Assert.AreEqual(newItem.EugenUserId, savedItem.EugenUserId);
            Assert.AreEqual(newItem.Name, savedItem.Name);
        }
Esempio n. 11
0
        public async Task <Dto.ApiResponse <object> > AssignRoleToUser(Dto.Role model)
        {
            var response = new Dto.ApiResponse <object>();

            var isRoleAlreadyassignedToUser = _userRoleRepo.List(i => i.RoleId == model.Id && i.UserId == model.UserId).Any();

            if (isRoleAlreadyassignedToUser)
            {
                response.Success = false;
                response.ErrorMesssage.Add(MtsResource.RoleAlreadyAssignToUser);
            }

            var userRoleEntity = _mapper.Map <Entity.UserRole>(model);

            userRoleEntity.RoleId = model.Id;

            await _userRoleRepo.Save(userRoleEntity);

            return(response);
        }
 public void GenerateEncryptionSymbolsData()
 {
     GetEncryptionSymbolsList().ForEach(item => _repo.AddWithoutSave(item));
     _repo.Save();
 }
Esempio n. 13
0
        public void ReplayTest()
        {
            GameMapTest();
            GameModeTest();
            GameTypeTest();
            VictoryConditionTest();

            var random = new Random((int)DateTime.Now.Ticks);

            var newReplay = new Replay
            {
                AI                 = true,
                Title              = GenerateRandomString(80),
                AllowObservers     = true,
                DateConstraint     = GenerateRandomString(12),
                GameMap            = GetFirst <GameMap>(),
                GameMode           = GetFirst <GameMode>(),
                GameType           = GetFirst <GameType>(),
                IncomeRate         = random.Next(100, 3000),
                InitMoney          = random.Next(100, 3000),
                IsNetworkMode      = true,
                MaxPlayers         = 32,
                NationConstraint   = GenerateRandomString(12),
                Private            = true,
                ScoreLimit         = random.Next(100, 3000),
                Seed               = GenerateRandomString(30),
                ServerName         = GenerateRandomString(30),
                ThematicConstraint = GenerateRandomString(15),
                UploadDate         = GetRandomDateTime(random),
                Version            = GenerateRandomString(12),
                VictoryCondition   = GetFirst <VictoryCondition>(),
                Link               = GenerateRandomString(255),
                FileHash           = Guid.NewGuid(),
                DownloadsCounter   = random.Next()
            };

            var repository = new CrudRepository <Replay>(_uow);

            repository.Save(newReplay);

            var savedReplay = repository.GetById(newReplay.Id);

            Assert.NotNull(savedReplay);
            Assert.AreEqual(newReplay.AI, savedReplay.AI);
            Assert.AreEqual(newReplay.AllowObservers, savedReplay.AllowObservers);
            Assert.AreEqual(newReplay.DateConstraint, savedReplay.DateConstraint);
            Assert.AreEqual(newReplay.GameMap.Id, savedReplay.GameMap.Id);
            Assert.AreEqual(newReplay.GameMode.Id, savedReplay.GameMode.Id);
            Assert.AreEqual(newReplay.GameType.Id, savedReplay.GameType.Id);
            Assert.AreEqual(newReplay.IncomeRate, savedReplay.IncomeRate);
            Assert.AreEqual(newReplay.InitMoney, savedReplay.InitMoney);
            Assert.AreEqual(newReplay.IsNetworkMode, savedReplay.IsNetworkMode);
            Assert.AreEqual(newReplay.MaxPlayers, savedReplay.MaxPlayers);
            Assert.AreEqual(newReplay.NationConstraint, savedReplay.NationConstraint);
            Assert.AreEqual(newReplay.Private, savedReplay.Private);
            Assert.AreEqual(newReplay.ScoreLimit, savedReplay.ScoreLimit);
            Assert.AreEqual(newReplay.Seed, savedReplay.Seed);
            Assert.AreEqual(newReplay.ServerName, savedReplay.ServerName);
            Assert.AreEqual(newReplay.ThematicConstraint, savedReplay.ThematicConstraint);
            Assert.AreEqual(newReplay.UploadDate, savedReplay.UploadDate);
            Assert.AreEqual(newReplay.Version, savedReplay.Version);
            Assert.AreEqual(newReplay.VictoryCondition.Id, savedReplay.VictoryCondition.Id);
            Assert.AreEqual(newReplay.Link, savedReplay.Link);
            Assert.AreEqual(newReplay.FileHash, savedReplay.FileHash);
            Assert.AreEqual(newReplay.DownloadsCounter, savedReplay.DownloadsCounter);
        }
Esempio n. 14
0
        public void PlayerTest()
        {
            PlayerUserTest();
            ReplayTest();

            var random = new Random((int)DateTime.Now.Ticks);

            var firstReplay = GetFirst <Replay>();

            var newItem = new Player
            {
                PlayerUser             = GetFirst <PlayerUser>(),
                PlayerAlliance         = random.Next(1, 20),
                PlayerAvatar           = GenerateRandomString(255),
                PlayerDeckContent      = GenerateRandomString(80),
                PlayerDeckName         = GenerateRandomString(25),
                PlayerElo              = random.Next(10000, 20000) / 100.0,
                PlayerIALevel          = GenerateRandomString(20),
                PlayerIncomeRate       = random.Next(1, 2000),
                PlayerIsEnteredInLobby = true,
                PlayerLevel            = random.Next(1, 2000),
                PlayerName             = GenerateRandomString(20),
                PlayerNumber           = random.Next(1, 100),
                PlayerRank             = random.Next(1, 20000),
                PlayerReady            = true,
                PlayerScoreLimit       = random.Next(1, 20000),
                PlayerTeamName         = GenerateRandomString(40)
            };

            firstReplay.Players = new List <Player> {
                newItem
            };
            newItem.Replay = firstReplay;

            var replayRepository = new CrudRepository <Replay>(_uow);

            replayRepository.Save(firstReplay);

            var repository = new CrudRepository <Player>(_uow);

            repository.Save(newItem);

            var savedReplay = replayRepository.GetById(firstReplay.Id);

            Assert.IsNotEmpty(savedReplay.Players);

            Assert.AreEqual(newItem.Id, savedReplay.Players.First().Id);

            var savedItem = repository.GetById(newItem.Id);

            Assert.NotNull(savedItem);
            Assert.AreEqual(newItem.PlayerAlliance, savedItem.PlayerAlliance);
            Assert.AreEqual(newItem.PlayerAvatar, savedItem.PlayerAvatar);
            Assert.AreEqual(newItem.PlayerDeckContent, savedItem.PlayerDeckContent);
            Assert.AreEqual(newItem.PlayerDeckName, savedItem.PlayerDeckName);
            Assert.AreEqual(newItem.PlayerElo, savedItem.PlayerElo);
            Assert.AreEqual(newItem.PlayerIALevel, savedItem.PlayerIALevel);
            Assert.AreEqual(newItem.PlayerIncomeRate, savedItem.PlayerIncomeRate);
            Assert.AreEqual(newItem.PlayerIsEnteredInLobby, savedItem.PlayerIsEnteredInLobby);
            Assert.AreEqual(newItem.PlayerLevel, savedItem.PlayerLevel);
            Assert.AreEqual(newItem.PlayerName, savedItem.PlayerName);
            Assert.AreEqual(newItem.PlayerNumber, savedItem.PlayerNumber);
            Assert.AreEqual(newItem.PlayerRank, savedItem.PlayerRank);
            Assert.AreEqual(newItem.PlayerReady, savedItem.PlayerReady);
            Assert.AreEqual(newItem.PlayerScoreLimit, savedItem.PlayerScoreLimit);
            Assert.AreEqual(newItem.PlayerTeamName, savedItem.PlayerTeamName);
            Assert.AreEqual(newItem.PlayerUser.Id, savedItem.PlayerUser.Id);
            Assert.AreEqual(newItem.Replay.Id, savedItem.Replay.Id);
        }
Esempio n. 15
0
        public async Task <ApiResponse <LoginDetail> > AuthenticateUser(UserLogin model)
        {
            var response = new ApiResponse <LoginDetail>();

            var userDetail = _userRepo.List(i => i.Email == model.Email).FirstOrDefault();
            var loginLog   = new Entity.LoginLog(model.IpAddress);

            if (userDetail != null && !userDetail.IsActive)
            {
                response.Success = false;
                response.ErrorMesssage.Add(MtsResource.AccountLocked);
                loginLog.Success = false;
            }

            if (response.Success)
            {
                if (userDetail == null || !_crypto.CheckMatch(userDetail.Password, model.Password))
                {
                    response.Success = false;
                    response.ErrorMesssage.Add(MtsResource.EmailPasswordNotFound);
                    if (userDetail != null)
                    {
                        loginLog.Success       = false;
                        loginLog.UserId        = userDetail.Id;
                        userDetail.ErrorCount += 1;
                        if (userDetail.ErrorCount == _config.MaxLoginErrorCount)
                        {
                            await DeactivateUser(userDetail);
                        }
                    }
                }
                if (response.Success)
                {
                    var userBusiness = _userBusinessRepo.List(i => i.UserId == userDetail.Id).FirstOrDefault();
                    if (userBusiness != null)
                    {
                        string chip = $"{model.Email}:{model.Password}";
                        loginLog.UserId       = userDetail.Id;
                        userDetail.ErrorCount = 0;
                        await _userRepo.Update(userDetail);

                        response.DataResponse = new LoginDetail()
                        {
                            BusinessId   = userBusiness.BusinessId,
                            Id           = userDetail.Id,
                            Name         = $"{userDetail.FirstName} {userDetail.LastName}",
                            RefreshToken = $"{_crypto.EncryptString(chip, _config.EncryptionKey)}.{_crypto.CalculateHash(chip)}",
                            AccessToken  = RandomGenerator.GenerateString(16)
                        };
                    }
                    else
                    {
                        response.Success = false;
                        response.ErrorMesssage.Add(MtsResource.EmailPasswordNotFound);
                    }
                }
            }

            await _loginLogRepo.Save(loginLog);

            return(response);
        }
        public async Task <int> Insert(SolicitudVacante solicitudVacanteAInsertar)
        {
            await repository.Save(solicitudVacanteAInsertar);

            return(solicitudVacanteAInsertar.Id);
        }