Ejemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] AgentDto agentDto, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var agentExist = await this.agentService.AnyAsync(t => t.Name == agentDto.Name, cancellationToken);

            if (agentExist)
            {
                return(BadRequest(ERROR_AGENT_EXIT));
            }

            var agent = this.mapper.Map <AgentDto, Agent>(agentDto);

            if (string.IsNullOrEmpty(agent.Script))
            {
                agent.Script = "return new ReconNess.Core.Models.ScriptOutput();";
            }

            await this.agentService.AddAgentAsync(agent, "Agent Added", cancellationToken);

            return(NoContent());
        }
Ejemplo n.º 2
0
        public bool UpdateAgent(AgentDto agentDto)
        {
            Entity agentEntity = new Entity("systemuser");

            string[]            columns = { "systemuserid" };
            ConditionExpression ce      = new ConditionExpression("internalemailaddress",
                                                                  ConditionOperator.Equal, agentDto.Contact.Email);

            FilterExpression fe = new FilterExpression();

            fe.AddCondition(ce);

            var ec = CrmServiceFactory.RetrieveEntities("systemuser", columns, fe, 1);

            if (ec.Entities.Count > 0)
            {
                agentEntity.Id = ec.Entities[0].Id;
                agentEntity["isw_freshdeskid"] = agentDto.Id.ToString();

                var a = UpdateEntity(agentEntity);

                return(a.Result);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public IActionResult GetAgent(int agentId)
        {
            Agent    agent    = _agentRepo.GetAgent(agentId);
            AgentDto agentDto = _mapper.Map <AgentDto>(agent);

            return(Ok(agentDto));
        }
Ejemplo n.º 4
0
        public ICollection <AgentCategory> Resolve(AgentDto source, Agent destination, ICollection <AgentCategory> member, ResolutionContext context)
        {
            var agentCategories = new List <AgentCategory>();

            source.Categories.ForEach(category =>
            {
                var categoryDb = this.categoryService.GetByCriteriaAsync(c => c.Name == category).Result;

                if (categoryDb != null)
                {
                    agentCategories.Add(new AgentCategory
                    {
                        CategoryId = categoryDb.Id
                    });
                }
                else
                {
                    agentCategories.Add(new AgentCategory
                    {
                        Category = new Category
                        {
                            Name = category
                        }
                    });
                }
            });

            return(agentCategories);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Put(Guid id, [FromBody] AgentDto agentDto, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var agent = await this.agentService.GetAgentWithCategoryAsync(t => t.Id == id, cancellationToken);

            if (agent == null)
            {
                return(NotFound());
            }

            if (agent.Name != agentDto.Name && await this.targetService.AnyAsync(t => t.Name == agentDto.Name))
            {
                return(BadRequest("There is an Agent with that name in the DB"));
            }

            agent.Name            = agentDto.Name;
            agent.AgentCategories = await this.categoryService.GetCategoriesAsync(agent.AgentCategories, agentDto.Categories, cancellationToken);

            agent.Command           = agentDto.Command;
            agent.IsBySubdomain     = agentDto.IsBySubdomain;
            agent.OnlyIfIsAlive     = agentDto.OnlyIfIsAlive;
            agent.OnlyIfHasHttpOpen = agentDto.OnlyIfHasHttpOpen;
            agent.SkipIfRanBefore   = agentDto.SkipIfRanBefore;
            agent.Script            = agentDto.Script;

            await this.agentService.UpdateAsync(agent, cancellationToken);

            return(NoContent());
        }
        public Task <AgentDto> Update(AgentDto agentDto)
        {
            Agent agent = ObjectMapper.Map <Agent>(agentDto);

            agent = _agentRepository.Update(agent);
            return(Task.FromResult <AgentDto>(agentDto));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Put(Guid id, [FromBody] AgentDto agentDto, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var agent = await this.agentService.GetAgentAsync(t => t.Id == id, cancellationToken);

            if (agent == null)
            {
                return(NotFound());
            }

            var agentExist = agent.Name != agentDto.Name && await this.agentService.AnyAsync(t => t.Name == agentDto.Name);

            if (agentExist)
            {
                return(BadRequest(ERROR_AGENT_EXIT));
            }

            agent.Name       = agentDto.Name;
            agent.Repository = agentDto.Repository;
            agent.Command    = agentDto.Command;
            agent.Script     = agentDto.Script;
            agent.AgentType  = agentDto.AgentType;
            agent.Categories = await this.categoryService.GetCategoriesAsync(agent.Categories, agentDto.Categories, cancellationToken);

            if (agent.AgentTrigger == null)
            {
                agent.AgentTrigger = new AgentTrigger();
            }

            agent.AgentTrigger.SkipIfRunBefore             = agentDto.TriggerSkipIfRunBefore;
            agent.AgentTrigger.TargetHasBounty             = agentDto.TriggerTargetHasBounty;
            agent.AgentTrigger.TargetIncExcName            = agentDto.TriggerTargetIncExcName;
            agent.AgentTrigger.TargetName                  = agentDto.TriggerTargetName;
            agent.AgentTrigger.RootdomainHasBounty         = agentDto.TriggerRootdomainHasBounty;
            agent.AgentTrigger.RootdomainIncExcName        = agentDto.TriggerRootdomainIncExcName;
            agent.AgentTrigger.RootdomainName              = agentDto.TriggerRootdomainName;
            agent.AgentTrigger.SubdomainHasBounty          = agentDto.TriggerSubdomainHasBounty;
            agent.AgentTrigger.SubdomainIsAlive            = agentDto.TriggerSubdomainIsAlive;
            agent.AgentTrigger.SubdomainIsMainPortal       = agentDto.TriggerSubdomainIsMainPortal;
            agent.AgentTrigger.SubdomainHasHttpOrHttpsOpen = agentDto.TriggerSubdomainHasHttpOrHttpsOpen;
            agent.AgentTrigger.SubdomainIncExcName         = agentDto.TriggerSubdomainIncExcName;
            agent.AgentTrigger.SubdomainName               = agentDto.TriggerSubdomainName;
            agent.AgentTrigger.SubdomainIncExcServicePort  = agentDto.TriggerSubdomainIncExcServicePort;
            agent.AgentTrigger.SubdomainServicePort        = agentDto.TriggerSubdomainServicePort;
            agent.AgentTrigger.SubdomainIncExcIP           = agentDto.TriggerSubdomainIncExcIP;
            agent.AgentTrigger.SubdomainIP                 = agentDto.TriggerSubdomainIP;
            agent.AgentTrigger.SubdomainIncExcTechnology   = agentDto.TriggerSubdomainIncExcTechnology;
            agent.AgentTrigger.SubdomainTechnology         = agentDto.TriggerSubdomainTechnology;
            agent.AgentTrigger.SubdomainIncExcLabel        = agentDto.TriggerSubdomainIncExcLabel;
            agent.AgentTrigger.SubdomainLabel              = agentDto.TriggerSubdomainLabel;

            await this.agentService.UpdateAgentAsync(agent, cancellationToken);

            return(NoContent());
        }
        public async Task <AgentDto> GetById(int id)
        {
            Agent result = await _agentRepository.GetAsync(id);

            AgentDto dto = ObjectMapper.Map <AgentDto>(result);

            return(dto);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 转换为代理实体
 /// </summary>
 /// <param name="dto">代理数据传输对象</param>
 public static Agent ToEntity(this AgentDto dto)
 {
     if (dto == null)
     {
         return(new Agent());
     }
     return(dto.MapTo(new Agent(dto.Id.ToGuid())));
 }
Ejemplo n.º 10
0
        public async Task <PageDto <AgentDto> > GetPageAsync(int pageSize, int pageNumber)
        {
            var page  = new PageDto <AgentDto>(pageSize, pageNumber);
            var items = await _unitOfWork.Agents.GetPageAsync(pageSize, pageNumber);

            page.SetData(items.Item2, items.Item1.Select(i => AgentDto.FromDomain(i)).ToList());
            return(page);
        }
Ejemplo n.º 11
0
        public void TestJson1()
        {
            AgentDto t = new AgentDto();

            t.commission = 1.234454M;

            string json = JsonConvert.SerializeObject(t);
        }
Ejemplo n.º 12
0
        public async Task <AgentDto> DeleteAsync(int id)
        {
            var agent = await Get(id);

            await Task.WhenAll(_unitOfWork.CompleteAsync((ctx) => ctx.Agents.Remove(agent)),
                               _cacheStore.RemoveAsync(GetCacheKey(id)));

            return(AgentDto.FromDomain(agent));
        }
        public Task <AgentDto> Create(AgentDto agentDto)
        {
            agentDto.CreatorUserId = AbpSession.UserId.Value;
            agentDto.CreationTime  = DateTime.Now;
            Agent agent = ObjectMapper.Map <Agent>(agentDto);

            agentDto.Id = _agentRepository.InsertAndGetId(agent);
            return(Task.FromResult <AgentDto>(agentDto));
        }
Ejemplo n.º 14
0
        public async Task <AgentDto> GetAsync(int id)
        {
            var agentDto = await _cacheStore.StoreAndGetAsync(GetCacheKey(id), async() =>
            {
                var agent = await Get(id);
                return(AgentDto.FromDomain(agent));
            });

            return(agentDto);
        }
Ejemplo n.º 15
0
        public AreaDto PutAgent(AgentDto agent)
        {
            var response = Client.PutAsJsonAsync($"api/Agents/{agent.Id}", agent).Result;

            if (response.IsSuccessStatusCode)
            {
                return(response.Content.ReadAsAsync <AreaDto>().Result);
            }
            return(null);
        }
Ejemplo n.º 16
0
        public async Task <CustomerRegistrationResponse> RegisterAgentAsync(AgentDto agent)
        {
            try
            {
                var customer = new Customer
                {
                    Id               = GenerateGuid().Result,
                    MainAddressId    = GenerateGuid().Result,
                    Firstname        = agent.Firstname,
                    Lastname         = agent.Lastname,
                    AgentBank        = agent.AgentBank,
                    AgentName        = agent.Firstname + " " + agent.Lastname,
                    AgentUserName    = agent.AgentUserName,
                    Dob              = agent.Dob,
                    IsAgent          = true,
                    Email            = agent.Email,
                    Password         = agent.Password,
                    Fax              = agent.Fax,
                    Gender           = agent.Gender,
                    IsCustomer       = false,
                    NewsLetterOpted  = false,
                    CustomerUserName = null,
                    Telephone        = agent.Telephone
                };
                GenericRepository <Customer> generic = new GenericRepository <Customer>(_context, this.dbSet, _httpContextAccessor);
                if (_context.Customers.Any(c => c.Email == customer.Email || c.AgentBank == customer.AgentBank || c.AgentUserName == customer.AgentUserName))
                {
                    var responseEmailExist = new CustomerRegistrationResponse
                    {
                        Response = "The Credentials supplied already exist",
                    };
                    return(responseEmailExist);
                }
                var responseSuccess = new CustomerRegistrationResponse
                {
                    Response = "Agent Details successfully added",
                };
                await generic.PostCustomer(customer);

                await _context.SaveChangesAsync();

                return(responseSuccess);
            }
            catch (Exception ex)
            {
                var responseException = new CustomerRegistrationResponse
                {
                    Response = ex.Message,
                };
                return(responseException);

                throw ex;
            }
        }
Ejemplo n.º 17
0
        public JsonResult SaveAgent([CustomizeValidator] AgentDto agentDto)
        {
            var p = new Agents()
            {
                Id    = agentDto.Id,
                Name  = agentDto.Name,
                Phone = agentDto.Phone
            };

            return(Json(_agentsRepository.Add(p).ToString()));
        }
        public void CreateAgent_PasswordIsValid(string password)
        {
            // Arrange
            var agent = new AgentDto()
            {
                Email = "*****@*****.**"
            };
            // Act
            var result = Validator.Validate(new CreateAgentCommand(agent, password));

            // Assert
            Assert.True(result.IsValid);
        }
        public void CreateAgent_AgentIsValid(string agentName, string password)
        {
            // Arrange
            var agent = new AgentDto()
            {
                UserName = agentName,
                Id       = "123"
            };
            // Act
            var result = Validator.Validate(new CreateAgentCommand(agent, password));

            // Assert
            Assert.True(result.IsValid);
        }
Ejemplo n.º 20
0
        public async Task <AgentDto> UpdateAsync(AgentDto dto)
        {
            await _unitOfWork.Agents.GuardForDuplicateEmailAddress(dto.Email, dto.Id);

            await _unitOfWork.Agents.GuardForDuplicatePhoneNumber(dto.PhoneNumber, dto.Id);

            var agent = await Get(dto.Id);

            agent.Update(dto.Email, dto.PhoneNumber, dto.Name, dto.Lastname);

            await Task.WhenAll(_unitOfWork.CompleteAsync(), _cacheStore.RemoveAsync(GetCacheKey(dto.Id)));

            return(dto);
        }
        public void GetAgentClaim_AgentIsValid(string userName)
        {
            // Arrange
            var agent = new AgentDto()
            {
                UserName = userName,
                Id       = "123"
            };
            // Act
            var result = Validator.Validate(new GetAgentClaimQuery(agent));

            // Assert
            Assert.True(result.IsValid);
        }
        public void CreateAgent_PasswordIsInvalid(string password)
        {
            // Arrange
            var agent = new AgentDto()
            {
                Email = "*****@*****.**"
            };
            // Act
            var result = Validator.Validate(new CreateAgentCommand(agent, password));

            // Assert
            Assert.Contains("Password required", result.Errors.First().ErrorMessage);
            Assert.False(result.IsValid);
        }
Ejemplo n.º 23
0
        public async Task CreateAgent_AgentNotCreated(string email, string password)
        {
            // Arrange
            var agent = new AgentDto()
            {
                Email = email
            };

            UserManager.Setup(u => u.CreateAsync(It.IsAny <NARE.Domain.Entities.Agent>(), It.IsAny <string>())).ReturnsAsync(IdentityResult.Failed());
            // Act
            var result = await Handler.Handle(new CreateAgentCommand(agent, password), CancellationToken.None);

            // Assert
            Assert.False(result.Succeeded);
        }
Ejemplo n.º 24
0
        public async Task <AgentDto> RetrieveAgentDto(string email, string name, string phoneNumber)
        {
            Agent agent = await _context.Agent.Include(x => x.Department)
                          .Include(x => x.Organization).FirstOrDefaultAsync(AgentMatches(email, name, phoneNumber));

            AgentDto agentDto = new AgentDto
            {
                AgentId         = agent.Id,
                Name            = agent.Name,
                ProfileImageUrl = agent.ProfileImgUrl,
                OrganisartionId = agent.Organization.Id
            };

            return(agentDto);
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> Post([FromBody] AgentDto agentDto, CancellationToken cancellationToken)
        {
            if (await this.agentService.AnyAsync(t => t.Name == agentDto.Name))
            {
                return(BadRequest("There is an Agent with that name in the DB"));
            }

            var agent = this.mapper.Map <AgentDto, Agent>(agentDto);

            agent.Script = "return new ReconNess.Core.Models.ScriptOutput();";

            await this.agentService.AddAsync(agent, cancellationToken);

            return(NoContent());
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> Post([FromBody] AgentDto agentDto, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var agent = this.mapper.Map <AgentDto, Agent>(agentDto);

            agent.Script = "return new ReconNess.Core.Models.ScriptOutput();";

            await this.agentService.AddAsync(agent, cancellationToken);

            return(NoContent());
        }
Ejemplo n.º 27
0
        public void GetAgentClaim_ReturnsEmpty()
        {
            // Arrange
            var agent = new AgentDto()
            {
                Email = "*****@*****.**"
            };
            var claims = new List <Claim>();

            UserManager.Setup(u => u.GetClaimsAsync(It.IsAny <NARE.Domain.Entities.Agent>())).ReturnsAsync(claims);
            // Act
            var returnedClaims = Handler.Handle(new GetAgentClaimQuery(agent), CancellationToken.None).Result;

            // Assert
            Assert.Empty(returnedClaims);
        }
Ejemplo n.º 28
0
        public async Task <AgentDto> CreateAsync(AgentDto dto)
        {
            await _unitOfWork.Agents.GuardForDuplicateEmailAddress(dto.Email);

            await _unitOfWork.Agents.GuardForDuplicatePhoneNumber(dto.PhoneNumber);

            var agent = new Agent(new PersonName(dto.Name, dto.Lastname)
                                  , dto.PhoneNumber, AgentSetting.CreateDefault()
                                  , dto.DepoId);

            agent.Register(dto.Email, _hasher.HashPassword(dto.Password));
            await _unitOfWork.CompleteAsync(ctx => ctx.Agents.AddAsync(agent));

            dto.Id       = agent.Id;
            dto.Password = null;
            return(dto);
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> Put(Guid id, [FromBody] AgentDto agentDto, CancellationToken cancellationToken)
        {
            var agent = await this.agentService.GetAgentWithCategoryAsync(t => t.Id == id, cancellationToken);

            if (agent == null)
            {
                return(NotFound());
            }

            if (agent.Name != agentDto.Name && await this.rootDomainService.AnyAsync(t => t.Name == agentDto.Name))
            {
                return(BadRequest("There is an Agent with that name in the DB"));
            }

            agent.Name            = agentDto.Name;
            agent.Repository      = agentDto.Repository;
            agent.AgentCategories = await this.categoryService.GetCategoriesAsync(agent.AgentCategories, agentDto.Categories, cancellationToken);

            agent.Command           = agentDto.Command;
            agent.IsBySubdomain     = agentDto.IsBySubdomain;
            agent.OnlyIfIsAlive     = agentDto.OnlyIfIsAlive;
            agent.OnlyIfHasHttpOpen = agentDto.OnlyIfHasHttpOpen;
            agent.SkipIfRanBefore   = agentDto.SkipIfRanBefore;
            agent.NotifyIfAgentDone = agentDto.NotifyIfAgentDone;
            agent.NotifyNewFound    = agentDto.NotifyNewFound;
            if (agent.AgentNotification == null)
            {
                agent.AgentNotification = new AgentNotification();
            }

            agent.AgentNotification.SubdomainPayload   = agentDto.SubdomainPayload;
            agent.AgentNotification.IpAddressPayload   = agentDto.IpAddressPayload;
            agent.AgentNotification.IsAlivePayload     = agentDto.IsAlivePayload;
            agent.AgentNotification.HasHttpOpenPayload = agentDto.HasHttpOpenPayload;
            agent.AgentNotification.TakeoverPayload    = agentDto.TakeoverPayload;
            agent.AgentNotification.DirectoryPayload   = agentDto.DirectoryPayload;
            agent.AgentNotification.ServicePayload     = agentDto.ServicePayload;
            agent.AgentNotification.NotePayload        = agentDto.NotePayload;

            agent.Script = agentDto.Script;

            await this.agentService.UpdateAsync(agent, cancellationToken);

            return(NoContent());
        }
Ejemplo n.º 30
0
        public void GetAgentClaim_ReturnsClaims(string key, string value)
        {
            // Arrange
            var agent = new AgentDto()
            {
                Email = "*****@*****.**"
            };
            var claims = new List <Claim>()
            {
                new Claim(key, value),
                new Claim(key, value),
                new Claim(key, value)
            };

            UserManager.Setup(u => u.GetClaimsAsync(It.IsAny <NARE.Domain.Entities.Agent>())).ReturnsAsync(claims);
            // Act
            var returnedClaims = Handler.Handle(new GetAgentClaimQuery(agent), CancellationToken.None).Result;

            // Assert
            Assert.Equal(3, returnedClaims.Count);
        }