Beispiel #1
0
        public void Map_Use_Defaults()
        {
            // Arrange
            var mapperConfiguration = new MapperConfiguration(expression => { expression.AddProfile <ClientMapperProfile>(); });
            var mapper = new AutoMapperWrapper(new Mapper(mapperConfiguration));
            var entity = new Entities.Client
            {
                ClientSecrets = new List <Entities.ClientSecret>
                {
                    new Entities.ClientSecret
                    {
                    }
                }
            };

            var def = new Models.Client
            {
                ClientSecrets = { new Models.Secret("foo") }
            };

            // Act
            var mappedModel = mapper.Map <Models.Client>(entity);

            // Assert
            Assert.Equal(def.ProtocolType, mappedModel.ProtocolType);
            Assert.Equal(def.ClientSecrets.First().Type, mappedModel.ClientSecrets.First().Type);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="clientName"></param>
        /// <returns></returns>
        public Entities.Client GetClientByName(string clientName)
        {
            var client = new Entities.Client();

            DbCommand dbCommand = null;

            using (dbCommand = database.GetStoredProcCommand(DBStoredProcedure.GetClientByName))
            {
                database.AddInParameter(dbCommand, "@client_name", DbType.String, clientName);

                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        var _client = new Entities.Client
                        {
                            ClientTypeId   = DRE.GetNullableInt32(reader, "client_type_id", 0),
                            ClientTypeName = DRE.GetNullableString(reader, "client_type", null),
                            ClientId       = DRE.GetNullableInt32(reader, "client_id", 0),
                            ClientName     = DRE.GetNullableString(reader, "client_name", null),
                            PANNo          = DRE.GetNullableString(reader, "pan_no", null)
                        };

                        client = _client;
                    }
                }
            }

            return(client);
        }
Beispiel #3
0
        public void AddClient(ClientRegistrationModel clientRegistration, int internalUserId)
        {
            var client = new Entities.Client()
            {
                FirstName     = clientRegistration.FirstName,
                LastName      = clientRegistration.LastName,
                PersonalId    = clientRegistration.PersonalId,
                ClientDetails = new Entities.ClientDetails()
                {
                    InternalUserId        = internalUserId,
                    CarRegistrationNumber = clientRegistration.CarRegistrationNumber,
                    DateOfBirth           = clientRegistration.DateOfBirth,
                    Email       = clientRegistration.Email,
                    PhoneNumber = clientRegistration.PhoneNumber,
                    Image       = clientRegistration.Image,
                    CarId       = clientRegistration.CarId,
                    TPLDetails  = new Entities.TPLDetails()
                    {
                        TPLTermId = clientRegistration.LiabilityTermId,
                        Status    = TplStatus.Unpaid
                    }
                }
            };

            _databaseContext.Clients.Add(client);
            _databaseContext.SaveChanges();
        }
        public void Properties_Map()
        {
            Client model = new Client {
                Properties = { { "foo1", "bar1" }, { "foo2", "bar2" } }
            };


            Entities.Client mappedEntity = model.ToEntity();

            mappedEntity.Properties.Count.Should().Be(2);
            KeyValuePair <string, string> foo1 = mappedEntity.Properties.FirstOrDefault(x => x.Key == "foo1");

            foo1.Should().NotBeNull();
            foo1.Value.Should().Be("bar1");
            KeyValuePair <string, string> foo2 = mappedEntity.Properties.FirstOrDefault(x => x.Key == "foo2");

            foo2.Should().NotBeNull();
            foo2.Value.Should().Be("bar2");


            Client mappedModel = mappedEntity.ToModel();

            mappedModel.Properties.Count.Should().Be(2);
            mappedModel.Properties.ContainsKey("foo1").Should().BeTrue();
            mappedModel.Properties.ContainsKey("foo2").Should().BeTrue();
            mappedModel.Properties["foo1"].Should().Be("bar1");
            mappedModel.Properties["foo2"].Should().Be("bar2");
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public bool DeleteClient(Entities.Client client, DbTransaction dbTransaction)
        {
            bool isDeleted = false;

            try
            {
                using (DbCommand dbCommand = database.GetStoredProcCommand(DBStoredProcedure.DeleteClient))
                {
                    database.AddInParameter(dbCommand, "@client_id", DbType.Int32, client.ClientId);
                    database.AddInParameter(dbCommand, "@modified_by", DbType.Int32, client.ModifiedBy);
                    database.AddInParameter(dbCommand, "@modified_by_ip", DbType.String, client.ModifiedByIP);

                    database.AddOutParameter(dbCommand, "@return_value", DbType.Int32, 0);

                    var result = database.ExecuteNonQuery(dbCommand, dbTransaction);

                    if (database.GetParameterValue(dbCommand, "@return_value") != DBNull.Value)
                    {
                        isDeleted = Convert.ToBoolean(database.GetParameterValue(dbCommand, "@return_value"));
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(isDeleted);
        }
Beispiel #6
0
        public void AcceptConnection()
        {
            socket.Listen(5);
            while (true)
            {
                Socket accepted = socket.Accept();
                SocketUserConnection userConnection = new SocketUserConnection(accepted);
                var user = userConnection.ReceiveData();

                // Logger
                Console.WriteLine($"[{DateTime.Now}] User connected. Name: {user.Name}");
                Console.Write($"[{DateTime.Now}] Connected users: ");
                foreach (var tmpClient in Clients)
                {
                    Console.Write($"{tmpClient.Name}, ");
                }

                IClient client = new Entities.Client
                {
                    Name   = user.Name,
                    socket = accepted,
                };

                lock (LockObject)
                {
                    Clients.Add(client);
                }
                Task.Factory.StartNew(() => ListenForChanges(client));
            }
        }
Beispiel #7
0
        public void Run()
        {
            using (var context = new Entities.SalesDbContext())
            {
                var client = new Entities.Client()
                {
                    Name = $"TestNameClient {context.Clients.Count()}"
                };
                var product = new Entities.Product {
                    Name = $"TestNameProduct {context.Products.Count()}"
                };
                var sales = new Entities.Sale {
                    Date = DateTime.Now, Client = client, Product = product, Summa = context.Clients.Count() + context.Products.Count()
                };

                context.Clients.Add(client);
                context.Products.Add(product);
                context.Sales.Add(sales);
                context.SaveChanges();
            }

            using (var context = new Entities.SalesDbContext())
            {
                var client  = context.Clients.OrderByDescending(x => x.Id).FirstOrDefault();
                var product = context.Products.OrderByDescending(x => x.Id).FirstOrDefault();
                var sale    = context.Sales.OrderByDescending(x => x.Id).FirstOrDefault();

                Console.WriteLine("---------------Last record---------------");
                Console.WriteLine($"{client.Id}, {client.Name}");
                Console.WriteLine($"{product.Id}, {product.Name}");
                Console.WriteLine($"{sale.Id}, Client [ {sale.Client.Id}, {sale.Client.Name} ] Item [ {sale.Product.Id} , {sale.Product.Name}], {sale.Summa}");
                Console.WriteLine("-----------------------------------------");
            }
        }
        private void ConnectToServer()
        {
            Console.WriteLine(ClientUI.Connecting());
            bool connected;

            do
            {
                Entities.Client client = AskForCredentials();
                SocketConnection = clientProtocol.ConnectToServer();
                object[] request = BuildRequest(Command.Login, client.Username, client.Password);
                SocketConnection.SendMessage(request);
                var response = new Response(SocketConnection.ReadMessage());
                connected = response.HadSuccess();
                if (connected)
                {
                    clientToken    = response.GetClientToken();
                    clientUsername = client.Username;
                    ClientUI.LoginSuccessful();
                }
                else
                {
                    Console.WriteLine(response.ErrorMessage());
                }
            } while (!connected);
        }
 private List <ClientVoteOptionModel> GetVoteOptions(Entities.Client client)
 {
     return(GetFibonacci().Select(item => new ClientVoteOptionModel
     {
         Number = item,
         Selected = client.Voted && client.VoteValue.HasValue && client.VoteValue.Value == item
     }).ToList());
 }
        internal Models.Client GetModel(Entities.Client entity, MapType mapType = MapType.Standard)
        {
            var model = new Models.Client();

            model.Id   = entity.Id;
            model.Name = entity.Name;
            return(model);
        }
        internal Entities.Client GetEntity(Models.Client model, MapType mapType = MapType.Standard)
        {
            var entity = new Entities.Client();

            entity.Id   = model.Id;
            entity.Name = model.Name;
            return(entity);
        }
 public static IdentityServer3.Core.Models.Client ToModel(this Entities.Client s)
 {
     if (s == null)
     {
         return(null);
     }
     return(Mapper.Map <Entities.Client, IdentityServer3.Core.Models.Client>(s));
 }
 public static RoomClientModel Convert(Entities.Client client)
 {
     return(new RoomClientModel
     {
         ClientId = client.ClientId,
         VoteValue = client.VoteValue,
         Name = client.Name,
         Voted = client.Voted
     });
 }
        public async Task <Client> FindClientByIdAsync(string clientId)
        {
            Model.Client    model  = null;
            Entities.Client entity = await StorageContext.GetEntityBlobAsync <Entities.Client>(clientId, StorageContext.ClientBlobContainer);

            model = entity?.ToModel();
            _logger.LogDebug("{clientName} found in blob storage: {clientFound}", clientId, model != null);

            return(model);
        }
        public void Can_Map()
        {
            Client model = new Client();

            Entities.Client mappedEntity = model.ToEntity();
            Client          mappedModel  = mappedEntity.ToModel();

            Assert.NotNull(mappedModel);
            Assert.NotNull(mappedEntity);
        }
Beispiel #16
0
        public static Client MapClient(Entities.Client ContextClient)
        {
            Client LogicClient = new Client(ContextClient.UserName, ContextClient.Email)
            {
                ClientID   = ContextClient.ClientID,
                Characters = ContextClient.Characters.Select(Mapper.MapCharacter).ToList()
            };

            return(LogicClient);
        }
Beispiel #17
0
        public static void SaveClient(int clientId, string clientName, string salesForceId)
        {
            using (var dc = new LicenseManagerClassesDataContext())
            {
                Entities.Client c = dc.Clients.SingleOrDefault(x => x.ID == clientId);
                c.ClientName   = clientName;
                c.SalesForceId = salesForceId;

                dc.SubmitChanges();
            }
        }
        public static ClientChatMeta MapClientChatMeta(Entities.Client contextClient)
        {
            ClientChatMeta logicMeta = new ClientChatMeta()
            {
                clientId       = contextClient.ClientId,
                clientNickname = contextClient.Nickname,
                hasAccount     = contextClient.HasAccount,
                isAdmin        = contextClient.IsAdmin
            };

            return(logicMeta);
        }
Beispiel #19
0
        public static Entities.Client MapClient(Client ContextClient)
        {
            Entities.Client EntitiesClient = new Entities.Client
            {
                UserName   = ContextClient.UserName,
                Email      = ContextClient.Email,
                ClientID   = ContextClient.ClientID,
                Characters = ContextClient.Characters.Select(Mapper.MapCharacter).ToList(),
                Games      = ContextClient.Games.Select(Mapper.MapGame).ToList()
            };

            return(EntitiesClient);
        }
Beispiel #20
0
 public void TestCreated()
 {
     _client = new Entities.Client()
     {
         Info = new ValueObjects.Info
         {
             Address = "Cr 25 # 7B Bis",
             Names   = "Carlos Andrés Catilla García",
             Phone   = "+573043541475"
         },
     };
     Console.WriteLine(_client.CreatedAt);
 }
Beispiel #21
0
        public static int CreateClient(string ClientName, string SalesForceId)
        {
            using (var dc = new LicenseManagerClassesDataContext())
            {
                Entities.Client c = new Entities.Client();
                c.ClientName   = ClientName;
                c.SalesForceId = SalesForceId;

                dc.Clients.InsertOnSubmit(c);
                dc.SubmitChanges();

                return(c.ID);
            }
        }
Beispiel #22
0
        public async Task UpdateAsync(Int32 clientId, Models.Client client)
        {
            if (clientId != client.Id)
            {
                throw new ArgumentException(nameof(clientId));
            }

            Entities.Client model = await _context.Clients.SingleOrDefaultAsync(p => p.Id == clientId);

            model         = client.ToEntity(model);
            model.Updated = DateTime.UtcNow;

            await _context.SaveChangesAsync();
        }
Beispiel #23
0
        public void RemoveRelPhoneClient(ClientPhoneModel model)
        {
            var client = new Entities.Client {
                ClientId = model.ClientId
            };
            var phone = new ClientPhone {
                ClientPhoneId = model.ClientPhoneId
            };

            client.ClientPhone.Add(phone);
            DbEntities.Client.Attach(client);
            client.ClientPhone.Remove(phone);
            DbEntities.SaveChanges();
        }
Beispiel #24
0
        private async Task <Models.Client> GetFromExpessionAsync <T>(T key, Expression <Func <Entities.Client, Boolean> > predicate)
        {
            Entities.Client client = await _context.Clients
                                     .Include(p => p.Policy)
                                     .ThenInclude(p => p.Roles)
                                     .Include(p => p.Policy)
                                     .ThenInclude(p => p.Permissions)
                                     .AsNoTracking()
                                     .FirstOrDefaultAsync(predicate);

            Models.Client model = client?.ToModel();

            _logger.LogDebug($"{key} found in database: {model != null}");

            return(model);
        }
        public void missing_values_should_use_defaults()
        {
            Entities.Client entity = new Entities.Client {
                ClientSecrets = new List <Secret> {
                    new Secret()
                }
            };

            Client def = new Client {
                ClientSecrets = { new Models.Secret("foo") }
            };

            Client model = entity.ToModel();

            model.ProtocolType.Should().Be(def.ProtocolType);
            model.ClientSecrets.First().Type.Should().Be(def.ClientSecrets.First().Type);
        }
        public void Map_Duplicated_Properties_ThrowsException()
        {
            var entity = new Entities.Client
            {
                Properties = new System.Collections.Generic.List <Entities.ClientProperty>
                {
                    new Entities.ClientProperty {
                        Key = "foo1", Value = "bar1"
                    },
                    new Entities.ClientProperty {
                        Key = "foo1", Value = "bar2"
                    },
                }
            };

            // Act & Assert
            Assert.ThrowsException <AutoMapperMappingException>(() => ClientMappers.ToModel(entity));
        }
Beispiel #27
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public List <Entities.Client> GetAllClients()
        {
            var clients = new List <Entities.Client>();

            DbCommand dbCommand = null;

            try
            {
                using (dbCommand = database.GetStoredProcCommand(DBStoredProcedure.GetAllClients))
                {
                    using (IDataReader reader = database.ExecuteReader(dbCommand))
                    {
                        while (reader.Read())
                        {
                            ClientAddress clientAddress = new ClientAddress();

                            var client = new Entities.Client
                            {
                                ClientTypeId     = DRE.GetNullableInt32(reader, "client_type_id", 0),
                                ClientTypeName   = DRE.GetNullableString(reader, "client_type", null),
                                ClientId         = DRE.GetNullableInt32(reader, "client_id", 0),
                                ClientCode       = DRE.GetNullableString(reader, "client_code", null),
                                ClientName       = DRE.GetNullableString(reader, "client_name", null),
                                PANNo            = DRE.GetNullableString(reader, "pan_no", null),
                                SrNo             = DRE.GetNullableInt64(reader, "sr_no", null),
                                ClientAddressess = clientAddress.GetAllClientAddressessByClientId(DRE.GetInt32(reader, "client_id"))
                            };

                            clients.Add(client);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbCommand = null;
            }

            return(clients);
        }
Beispiel #28
0
        public void ToModel_MapsAllowedIdentityTokenSigningAlgorithms()
        {
            var client = new Entities.Client()
            {
                AllowedIdentityTokenSigningAlgorithms = "HS256,ES256"
            };

            var entity = client.ToModel();

            Assert.NotNull(entity.AllowedIdentityTokenSigningAlgorithms);
            Assert.NotEmpty(entity.AllowedIdentityTokenSigningAlgorithms);

            var algorithms   = entity.AllowedIdentityTokenSigningAlgorithms.ToList();
            var algorithmOne = algorithms[0];
            var algorithmTwo = algorithms[1];

            Assert.Equal("HS256", algorithmOne);
            Assert.Equal("ES256", algorithmTwo);
        }
 /// <summary>
 /// maps a logic client to a context client
 /// </summary>
 /// <param name="logicClient"></param>
 /// <returns></returns>
 public static Data.Entities.Client MapClient(Logic.Objects.Client logicClient)
 {
     Entities.Client contextClient = new Entities.Client()
     {
         ClientId       = logicClient.clientID,
         ClientName     = logicClient.clientName,
         Email          = logicClient.email,
         Nickname       = logicClient.nickname,
         ClientStatusId = logicClient.clientStatus.statusID,
         AddressLine1   = logicClient.address.addressLineOne,
         AddressLine2   = logicClient.address.addressLineTwo,
         City           = logicClient.address.city,
         State          = logicClient.address.state,
         PostalCode     = logicClient.address.postalCode,
         Country        = logicClient.address.country,
         IsAdmin        = logicClient.isAdmin,
         HasAccount     = logicClient.hasAccount
     };
     return(contextClient);
 }
        public static IdentityServer3.Core.Models.Client ToModel(this Entities.Client s)
        {
            if (s == null)
            {
                return(null);
            }
            if (s.ClientSecrets == null)
            {
                s.ClientSecrets = new List <Entities.ClientSecret>();
            }
            if (s.RedirectUris == null)
            {
                s.RedirectUris = new List <Entities.ClientRedirectUri>();
            }
            if (s.PostLogoutRedirectUris == null)
            {
                s.PostLogoutRedirectUris = new List <Entities.ClientPostLogoutRedirectUri>();
            }
            if (s.AllowedScopes == null)
            {
                s.AllowedScopes = new List <Entities.ClientScope>();
            }
            if (s.IdentityProviderRestrictions == null)
            {
                s.IdentityProviderRestrictions = new List <Entities.ClientIdPRestriction>();
            }
            if (s.Claims == null)
            {
                s.Claims = new List <Entities.ClientClaim>();
            }
            if (s.AllowedCustomGrantTypes == null)
            {
                s.AllowedCustomGrantTypes = new List <Entities.ClientCustomGrantType>();
            }
            if (s.AllowedCorsOrigins == null)
            {
                s.AllowedCorsOrigins = new List <Entities.ClientCorsOrigin>();
            }

            return(Mapper.Map <Entities.Client, IdentityServer3.Core.Models.Client>(s));
        }