/// <summary>
        /// Create client for particular bank
        /// </summary>
        /// <param name="clientDto"></param>
        /// <returns></returns>
        public async Task <ClientResponseDto> CreateClient(ClientRequestDto clientDto)
        {
            try
            {
                var userEntity    = _mapper.Map <User>(clientDto);
                var clientEntity  = _mapper.Map <Client>(clientDto);
                var usernameExist = _bankContext.Users.FirstOrDefault(x => x.UserName == userEntity.UserName);
                if (usernameExist != null)
                {
                    throw new Exception("Username is already taken");
                }
                userEntity.CreatedDate = DateTime.Now;
                _bankContext.Add(userEntity);
                _bankContext.SaveChanges();

                clientEntity.UserId      = userEntity.Id;
                clientEntity.CreatedDate = DateTime.Now;
                _bankContext.Add(clientEntity);
                _bankContext.SaveChanges();

                return(new ClientResponseDto
                {
                    UserName = userEntity.UserName,
                    ClientId = clientEntity.Id,
                    UserId = userEntity.Id
                });
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public async Task <IActionResult> addNode(ClientRequestDto clientRequestDto)
        {
            try{
                var nodeServiceResponse = await _nodeService.pingNode(clientRequestDto.host, clientRequestDto.port);

                if (nodeServiceResponse != null)
                {
                    var thresholdStatus = await _nodeService.setThreshold(clientRequestDto.host, clientRequestDto.port, clientRequestDto.downloadThreshold, clientRequestDto.uploadThreshold);

                    if (thresholdStatus != null && thresholdStatus.success == true)
                    {
                        var newNode = await _repo.AddNode(clientRequestDto.host, clientRequestDto.port, clientRequestDto.userName, nodeServiceResponse.status, clientRequestDto.networkId, nodeServiceResponse.startTime, clientRequestDto.uploadThreshold, clientRequestDto.downloadThreshold);

                        if (newNode != null)
                        {
                            Ok(newNode);
                        }
                        else
                        {
                            BadRequest("Node already exists in this network");
                        }
                    }
                    else
                    {
                        BadRequest("Failed to update threshold values");
                    }
                }
                return(Ok(nodeServiceResponse));
            } catch (Exception ex) {
                return(StatusCode(500, "Internal server error"));
            }
        }
        public async Task <Infrastructure.Models.Client> CreateClientAsync(ClientRequestDto client)
        {
            var entry = await _dbContext.Clients.AddAsync(new Infrastructure.Models.Client
            {
                FullName = client.FullName,
                TicketId = client.TicketId
            });

            await _dbContext.SaveChangesAsync();

            return(entry.Entity);
        }
        public IEnumerable <Client> GetClients(ClientRequestDto req)
        {
            Expression <Func <Client, bool> > predicate = c => true;

            if (!string.IsNullOrEmpty(req.Name))
            {
                predicate = predicate.And(p => p.FirstName.Contains(req.Name) || p.MiddleName.Contains(req.Name) || p.LastName.Contains(req.Name) || p.FirstNameAr.Contains(req.Name) || p.MiddleNameAr.Contains(req.Name) || p.LastNameAr.Contains(req.Name));
            }
            if (!string.IsNullOrEmpty(req.Email))
            {
                predicate = predicate.And(p => p.Email == req.Email);
            }
            if (!string.IsNullOrEmpty(req.PhoneNumber))
            {
                predicate = predicate.And(p => p.PhoneNumber == req.PhoneNumber);
            }
            if (!string.IsNullOrEmpty(req.BirthDate))
            {
                predicate = predicate.And(p => p.BirthDate == req.BirthDate);
            }
            if (req.NationalityId != null)
            {
                predicate = predicate.And(p => p.NationalityId == req.NationalityId);
            }
            if (req.IdentityNumber != null)
            {
                predicate = predicate.And(p => p.IdentityNumber == req.IdentityNumber);
            }
            if (req.EducationLevelId != null)
            {
                predicate = predicate.And(p => p.EducationLevelId == req.EducationLevelId);
            }
            if (req.IdentityTypeId != null)
            {
                predicate = predicate.And(p => p.IdentityTypeId == req.IdentityTypeId);
            }
            if (req.DateFrom != null && req.DateTo != null)
            {
                predicate = predicate.And(p => p.CreatedDate.Date >= req.DateFrom.Value.Date && p.CreatedDate.Date <= req.DateTo.Value.Date);
            }
            var data = this.GetMany(predicate)
                       .Include("IdentityType").Include("Gender").Include("IdentityIssuePlace")
                       .Include("WorkCity").Include("Nationality").Include("SocialStatus")
                       .Include("SocialStatus").Include("EducationLevel").Include("QuotationsMotorRequests").Include("PolicyRequests").Include("ApplicationUser").OrderBy(o => o.CreatedDate).OrderBy(o => o.CreatedBy);

            return(data);
        }
Exemple #5
0
        public void Post([FromBody] ClientRequestDto dto)
        {
            lock (_context)
            {
                var client = new Client
                {
                    Hash         = dto.Hash,
                    Type         = dto.Type,
                    Amount       = dto.Amount,
                    StartDate    = dto.StartDate,
                    Transactions = new List <Transaction>(),
                    AddDate      = DateTime.Now
                };
                var foundClient = _context.Clients.FirstOrDefault(c => c.Hash == dto.Hash);
                if (foundClient != null)
                {
                    foundClient.Hash       = dto.Hash;
                    foundClient.Type       = dto.Type;
                    foundClient.Amount     = dto.Amount;
                    foundClient.UpdateDate = DateTime.Now;
                    client = foundClient;
                }

                var blocks = _context.Blocks
                             .Where(b => dto.MinedBlocksHashes?.Contains(b.Hash) == true)
                             .ToList();

                blocks.ForEach(b =>
                {
                    b.Miner      = client;
                    b.UpdateDate = DateTime.Now;
                });
                client.MinedBlocks = blocks;

                if (_context.Clients.All(c => c.Hash != client.Hash))
                {
                    _context.Clients.Add(client);
                }
            }
        }
        public async Task <ClientResponseDto> CreateClient(ClientRequestDto client)
        {
            var result = await _clientService.CreateClientAsync(client);

            return(_mapper.Map <ClientResponseDto>(result));
        }
        public async Task <ClientResponseDto> UpdateClient(long clientId, ClientRequestDto client)
        {
            var result = await _clientService.UpdateClientAsync(clientId, client);

            return(_mapper.Map <ClientResponseDto>(result));
        }
        public async Task <Infrastructure.Models.Client> UpdateClientAsync(long clientId, ClientRequestDto client)
        {
            var entity = await _dbContext.Clients.SingleOrDefaultAsync(c => c.Id == clientId);

            entity.FullName = client.FullName;
            await _dbContext.SaveChangesAsync();

            return(entity);
        }
 /// <summary>
 /// Create client
 /// </summary>
 /// <param name="clientDto"></param>
 /// <returns></returns>
 public async Task <ClientResponseDto> CreateClient(ClientRequestDto clientDto)
 {
     return(await _clientRepository.CreateClient(clientDto));
 }
        public async Task <ClientResponseDto> CreateClient(ClientRequestDto clientRequestDto)
        {
            var client = await _clientService.CreateClient(clientRequestDto);

            return(client);
        }