Ejemplo n.º 1
0
        public async Task <ActionResult> PostFreelancer(FreelancerViewModel vm)
        {
            string res = User.Claims.First(x => x.Type == "UserId").Value;

            int id = int.Parse(res);

            vm.UserId = id;

            var freelancer = new Domain.Entities.Freelancer()
            {
                UserForeignKey = id, PayHourly = vm.PayHourly
            };
            await freelancerService.AddAsync(freelancer);

            await clientService.AddAsync(vm.CompanyName, id);

            var user = await userService.GetAsync(id);

            var token = await tokenService.GenerateToken(user, appSettings.JWT_Secret, vm.Password);

            //Update freelancerId and skillId of Skills
            var skillsUsers = vm.SkillUsers.Select(c => new SkillUser {
                FreelancerId = user.Freelancer.Id, SkillId = c.Skill.Id
            }).ToList();
            await skillService.AddRangeAsync(skillsUsers);

            if (token == "")
            {
                return(BadRequest());
            }


            return(Ok(new { token }));
        }
Ejemplo n.º 2
0
        public async Task AddClientAsync()
        {
            string              a       = "secret".Sha512();
            IClientService      service = Startup.CreateCluster().GrainFactory.GetGrain <IClientService>("@");
            ClientAddRequestDto dto     = new ClientAddRequestDto
            {
                ClientName  = "OTC客户端",
                ClientUri   = "https://otc1.zgzop.com",
                MerchantId  = "10000",
                Description = "OTC客户端",
                LoginUri    = "https://otc1.zgzop.com/login"
            };

            dto.AllowedGrantTypes.Add(GrantType.ClientCredentials);
            dto.AllowedScopes.Add("profile");
            dto.AllowedScopes.Add("phone");
            dto.AllowedScopes.Add("openid");
            dto.AllowedScopes.Add("UC_API");
            dto.AllowedScopes.Add("OTC_API");
            dto.AllowedScopes.Add("OT_API");
            var secret = new DTO.SecretDto("Gcyayx5tX2x12Vhp07BJuoAqXG8P4mUY", "OTC客户端-Gcyayx5tX2x12Vhp07BJuoAqXG8P4mUY", Convert.ToDateTime("2030-01-01 12:12:12"));

            dto.Secrets.Add(secret);
            var response = await service.AddAsync(dto);
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> PostClient(ClientDto clientDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try {
                Client client = new Client();

                client.FirstName = clientDto.FirstName;
                client.LastName  = clientDto.LastName;

                client = await _clientService.AddAsync(client);

                clientDto.Id = client.Id;

                return(CreatedAtRoute("ApiRoute", new { id = clientDto.Id }, clientDto));
            }
            catch (DbUpdateConcurrencyException)
            {
                //Log something her...
                return(InternalServerError());
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <ClienteDTO> > Post([FromBody] ClienteAddDTO request)
        {
            var cliente = _mapper.Map <ClienteAddDTO, Cliente>(request);
            await _clientService.AddAsync(cliente);

            var clienteDTO = _mapper.Map <Cliente, ClienteDTO>(cliente);

            return(CreatedAtAction("Get", new { id = cliente.Id }, clienteDTO));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Add(ClientDto clientDto)
        {
            using (var logger = _loggerManager.CreateLogger())
            {
                await _clientService.AddAsync(clientDto);

                logger.LogInformation($"Client {clientDto.ClientName} is added successfully.");
                return(Ok());
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Post([FromBody] Client client)
        {
            // Validate
            if (!ModelState.IsValid)
            {
                return(BadRequest("Required fields are empty."));
            }

            await _clientService.AddAsync(client);

            return(Ok());
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Add([FromBody] AddClientRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var response = await _clientService.AddAsync(request);

            if (!response.IsValid)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(response));
        }
        public async Task <IActionResult> Create(ClientInputModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await _clientService.AddAsync(UserId, model.ClientName, model.RedirectUrl, model.PostLogoutRedirectUrl, model.RequireConsent);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, result.ErrorMsg);
                }
            }

            return(View(model));
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> Create(ClientViewModel clientViewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(clientViewModel));
                }

                await _clientService.AddAsync(_mapper.Map <ClientDTO>(clientViewModel))
                .ConfigureAwait(false);

                return(RedirectToAction("Index"));
            }
            catch (Exception exception)
            {
                ViewBag.Error = exception.Message;

                return(View());
            }
        }
Ejemplo n.º 10
0
 public async Task Post([FromBody] Client value)
 {
     await _clientService.AddAsync(value);
 }
        public async Task <IActionResult> Post([FromBody] Client client)
        {
            var added = await _clientService.AddAsync(client);

            return(StatusCode(StatusCodes.Status200OK, added));
        }