예제 #1
0
        public ClientsDto SaveClient(ClientsDto client)
        {
            using (var db = new GapInsuranceDBModel())
            {
                Clients dbClient;

                if (client.Id > 0)
                {
                    dbClient = db.Clients.FirstOrDefault(x => x.Id == client.Id);

                    if (dbClient == null)
                    {
                        throw new KeyNotFoundException("Client doesn't exists");
                    }
                }
                else
                {
                    dbClient = new Clients();
                    db.Clients.Add(dbClient);
                }

                dbClient.Name = client.Name;

                db.SaveChanges();

                return(Mapper.Map <Clients, ClientsDto>(dbClient));
            }
        }
예제 #2
0
        /// <summary>
        /// 编辑信息
        /// </summary>
        public async Task EditModel(ClientsDto input)
        {
            try
            {
                _dbContext.Ado.BeginTran();
                var model = _mapper.Map <ClientsDto, Clients>(input);
                if (model.Id > 0)
                {
                    await _dbContext.Updateable(model).ExecuteCommandAsync();
                    await SaveClientGrantTypes(input.AllowedGrantTypes, model.Id, true);
                    await SaveClientScope(input.AllowedScopes, model.Id, true);
                    await SaveClientSecret(input.ClientSecrets, model.Id, true);

                    _dbContext.Ado.CommitTran();
                    return;
                }
                var mid = await _dbContext.Insertable(model).ExecuteReturnIdentityAsync();
                await SaveClientGrantTypes(input.AllowedGrantTypes, mid);
                await SaveClientScope(input.AllowedScopes, mid);
                await SaveClientSecret(input.ClientSecrets, mid);

                _dbContext.Ado.CommitTran();
            }
            catch (Exception ex)
            {
                _dbContext.Ado.RollbackTran();
                throw ex;
            }
        }
예제 #3
0
        public async Task <string> UpdatePhoto(ClientsDto photo)
        {
            var url    = $"{Settings.SERVER_ENDPOINT}/Clients/UpdatePhoto";
            var result = await _requestService.PutAsync <ClientsDto, string>(url, photo);

            return(result);
        }
예제 #4
0
        public async void ObtenerClients(string url)
        {
            HttpClient           httpClients = new HttpClient();
            List <ClientsEntity> listado     = new List <ClientsEntity>();

            try
            {
                HttpResponseMessage response = httpClients.GetAsync(url).Result;

                if (response.IsSuccessStatusCode)
                {
                    var JsonString = await response.Content.ReadAsStringAsync();

                    DataSet   deserialized = JsonConvert.DeserializeObject <DataSet>(JsonString);
                    DataTable dataTable    = deserialized.Tables["Clients"];

                    foreach (DataRow row in dataTable.Rows)
                    {
                        ClientsDto clientDto = new ClientsDto(row["id"].ToString(), row["name"].ToString(), row["email"].ToString(), row["role"].ToString());
                        listado.Add(MapperApplicationClients.ClientDtoToClientEntity(clientDto));
                    }

                    PersistirDatosRepository.PersistirDatosClients(listado);
                }
            }
            catch (VuelingExceptions ex)
            {
                throw ex;
            }
        }
예제 #5
0
        public async Task <ActionResult> UpdateClient(int id, ClientsDto body)
        {
            await _DataClients.UpdateClient(id, body);

            // Retorna un 204
            return(NoContent());
        }
        public void WhenIModifyTheValueOfTheLastNameToBe(string lastName)
        {
            var client    = this.mongoDbHelper.Client;
            var newClient = new ClientsDto(client.FirstName, lastName, client.Addresses);

            this.mongoDbHelper.UpdateClient(client, newClient);
        }
예제 #7
0
        public async Task <IActionResult> EditAsync([FromBody] ClientsDto input)
        {
            await _business.EditModel(input);

            return(Ok(new MsgResultDto {
                Success = true
            }));
        }
예제 #8
0
        public async Task UpdateClient(int id, ClientsDto body)
        {
            var entry = await _context.Clients.SingleAsync(x => x.IdClient == id);

            entry.Name = body.Name;

            await _context.SaveChangesAsync();
        }
예제 #9
0
        public IActionResult GetClients(string app)
        {
            var response = ClientsDto.FromApp(App, this);

            Response.Headers[HeaderNames.ETag] = App.Version.ToString();

            return(Ok(response));
        }
예제 #10
0
        private async Task <ClientsDto> InvokeCommandAsync(ICommand command)
        {
            var context = await CommandBus.PublishAsync(command);

            var result   = context.Result <IAppEntity>();
            var response = ClientsDto.FromApp(result, this);

            return(response);
        }
예제 #11
0
        public IHttpActionResult Post([FromBody] ClientsDto client)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var updatedClient = clientManager.SaveClient(client);

            return(Ok(updatedClient));
        }
예제 #12
0
        public async Task <ActionResult> CreateClient(ClientsDto body)
        {
            var result = await _DataClients.CreateClient(body);

            // Retorna un 201
            return(CreatedAtAction(
                       "GetClientById",
                       new { id = result.IdClient },
                       result
                       ));
        }
예제 #13
0
        public IActionResult GetClients(string app)
        {
            var response = Deferred.Response(() =>
            {
                return(ClientsDto.FromApp(App, this));
            });

            Response.Headers[HeaderNames.ETag] = App.ToEtag();

            return(Ok(response));
        }
예제 #14
0
        public async Task <IActionResult> Clients(int?page, string search)
        {
            ViewBag.Search = search;
            ClientsDto clients = await _clientService.GetClientsAsync(search, page ?? 1);

            if (!await _authorization.IsAdmin(User))
            {
                clients = await _clientManagerService.GetManagedClients(User.GetSubjectId(), search, page ?? 1, 10);
            }
            return(View(clients));
        }
예제 #15
0
 public IHttpActionResult EditClientDataBase(ClientsDto client)
 {
     try
     {
         _bllFactory.UserBll.EditClientDataBase(client);
         return(Ok(true));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("error", ex.Message);
         return(BadRequest(ModelState));
     }
 }
        public IActionResult GetProjectWithDailyActivitiesDto()
        {
            List <ProjectWithDailyActivitiesDto> final_result = new List <ProjectWithDailyActivitiesDto>();

            foreach (var e in _context.Project)
            {
                var client = new ClientsDto()
                {
                    ClientId       = e.Client.ClientId,
                    Name           = e.Client.Name,
                    PhoneNumber    = e.Client.PhoneNumber,
                    Email          = e.Client.Email,
                    CIF            = e.Client.CIF,
                    CountryId      = e.Client.CountryId,
                    Country        = e.Client.Country,
                    City           = e.Client.City,
                    Address        = e.Client.Address,
                    IBAN           = e.Client.IBAN,
                    Bank           = e.Client.Bank,
                    IsActiveClient = e.Client.IsActiveClient
                };


                var epproject = from epr in e.EmployeeProject
                                select new EmployeeDto()
                {
                    EmployeeId = epr.EmployeeId,
                    FirstName  = epr.Employee.FirstName,
                    LastName   = epr.Employee.LastName,
                    Department = epr.Employee.Department,
                    Function   = epr.Employee.Function
                };

                final_result.Add(new ProjectWithDailyActivitiesDto()
                {
                    ProjectId       = e.ProjectId,
                    Name            = e.Name,
                    StartDate       = e.StartDate,
                    EndDate         = e.EndDate,
                    AgreementUrl    = e.AgreementUrl,
                    ClientId        = e.ClientId,
                    Client          = client,
                    IsChargeable    = e.IsChargeable,
                    DailyActivities = e.DailyActivities,
                    EmployeeProject = epproject
                });
            }

            return(Ok(final_result));
        }
        /// <summary>
        /// The delete document.
        /// </summary>
        /// <param name="client">describe client parameter on DeleteDocument.</param>
        public void DeleteDocument(ClientsDto client)
        {
            var numbers     = client.Addresses.Select(bidResult => bidResult.Number).ToList();
            var streets     = client.Addresses.Select(bidResult => bidResult.Street).ToList();
            var postalCodes = client.Addresses.Select(bidResult => bidResult.PostalCode).ToList();

            var builder = Builders <ClientsDto> .Filter;
            var filter  = builder.Eq(x => x.FirstName, client.FirstName)
                          & builder.Eq(x => x.LastName, client.LastName)
                          & builder.Eq(x => x.Addresses, client.Addresses)
                          & builder.ElemMatch(x => x.Addresses, el => numbers.Contains(el.Number) && (streets.Contains(el.Street) && postalCodes.Contains(el.PostalCode)));

            this.collection.DeleteOneAsync(filter).Wait();
        }
예제 #18
0
        public async Task <ClientsDto> CreateClient(ClientsDto body)
        {
            var entry = new Clients
            {
                Name = body.Name
            };

            await _context.AddAsync(entry);

            await _context.SaveChangesAsync();

            // Retorno el objeto que ha sido procesado para la creación
            return(_mapper.Map <ClientsDto>(entry));
        }
예제 #19
0
        public ApiResponse <bool> EditClient(ClientsDto client)
        {
            if (client == null)
            {
                return(new ApiResponse <bool>(responseStatusCode: RestStatusCode.NotFound));
            }

            using (_uow.BeginTransaction())
            {
                var clientRepo = _uow.ClientsRepository.GetById(client.Id);
                client.MergeObjects(clientRepo);
                _uow.ClientsRepository.Update(clientRepo);
                _uow.CommitTransaction();
            }

            return(new ApiResponse <bool>(responseResult: true));
        }
        /// <summary>
        /// The update element in database function.
        /// </summary>
        /// <param name="client">client to be updated.</param>
        /// <param name="newClient">new value for the client.</param>
        public void UpdateClient(ClientsDto client, ClientsDto newClient)
        {
            var numbers     = client.Addresses.Select(bidResult => bidResult.Number).ToList();
            var streets     = client.Addresses.Select(bidResult => bidResult.Street).ToList();
            var postalCodes = client.Addresses.Select(bidResult => bidResult.PostalCode).ToList();

            var builder = Builders <ClientsDto> .Filter;
            var filter  = builder.Eq(x => x.FirstName, client.FirstName)
                          & builder.Eq(x => x.LastName, client.LastName)
                          & builder.Eq(x => x.Addresses, client.Addresses)
                          & builder.ElemMatch(x => x.Addresses, el => numbers.Contains(el.Number) && streets.Contains(el.Street) && postalCodes.Contains(el.PostalCode));

            var update = Builders <ClientsDto> .Update.Set(s => s.FirstName, newClient.FirstName)
                         .Set(s => s.LastName, newClient.LastName)
                         .Set(s => s.Addresses, newClient.Addresses);

            this.collection.UpdateOneAsync(filter, update).Wait();
        }
예제 #21
0
        public IHttpActionResult Get(string id)
        {
            try
            {
                ClientsDto client = clientsService.GetById(id);

                if (client != null)
                {
                    return(Ok(client));
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
            }
            catch (VuelingExceptions ex)
            {
                throw new VuelingExceptions("No se han podido obtener los clientes.", ex);
            }
        }
예제 #22
0
        public IHttpActionResult GetByName(string name)
        {
            try
            {
                ClientsDto client = clientsService.GetByName(name);

                if (client != null)
                {
                    return(Ok(client));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (VuelingExceptions ex)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
        }
예제 #23
0
        public IHttpActionResult ClientByPolicyNumber(string number)
        {
            try
            {
                ClientsDto clientDto = clientsService.GetByPolicyNumber(number);

                if (clientDto != null)
                {
                    return(Ok(clientDto));
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
            }
            catch (VuelingExceptions ex)
            {
                throw new VuelingExceptions("No se han podido obtener los clientes.", ex);
            }
        }
        /// <summary>
        /// Gets the employee.
        /// </summary>
        /// <returns>The ClientsDto object.</returns>
        public ClientsDto GetEmployee()
        {
            var numbers     = this.Client.Addresses.Select(bidResult => bidResult.Number).ToList();
            var streets     = this.Client.Addresses.Select(bidResult => bidResult.Street).ToList();
            var postalCodes = this.Client.Addresses.Select(bidResult => bidResult.PostalCode).ToList();

            var builder = Builders <ClientsDto> .Filter;
            var filter  = builder.Eq(x => x.FirstName, this.Client.FirstName)
                          & builder.Eq(x => x.LastName, this.Client.LastName)
                          & builder.Eq(x => x.Addresses, this.Client.Addresses)
                          & builder.Eq(x => x._id, this.Client._id)
                          & builder.ElemMatch(x => x.Addresses, el => numbers.Contains(el.Number) &&
                                              (streets.Contains(el.Street) &&
                                               postalCodes.Contains(el.PostalCode)));

            // Testing of mongodb filters var renderedFilter =
            var result = this.collection.FindAsync(filter).Result.ToList();

            this.matchFound = result.Count > 0 ? result[0] : null;
            return(result.Count > 0 ? result[0] : null);
        }
        public void GetAllTest()
        {
            List <ClientsDto> listado = new List <ClientsDto>();

            // Apartado Selenium
            browser.Navigate().GoToUrl("http://localhost:60480/api/Clients");

            var responseElement = browser.FindElements(By.TagName("ClientsDto"));

            foreach (var n in responseElement)
            {
                var nombre = n.FindElement(By.TagName("nombre"));
                var email  = n.FindElement(By.TagName("email"));
                var id     = n.FindElement(By.TagName("id"));
                var role   = n.FindElement(By.TagName("role"));

                ClientsDto client = new ClientsDto(id.ToString(), nombre.ToString(), email.ToString(), role.ToString());
                listado.Add(client);
            }

            Assert.IsTrue(listado != null);
        }
예제 #26
0
        public ApiResponse <long> CreateNewClient(ClientsDto client)
        {
            if (client == null)
            {
                return new ApiResponse <long> {
                           ResponseStatusCode = RestStatusCode.NotFound
                }
            }
            ;

            var  clientApi = client.ToRepo <Clients>();
            long clientId;

            using (_uow.BeginTransaction())
            {
                clientId = _uow.ClientsRepository.Create(clientApi);

                _uow.CommitTransaction();
            }

            return(new ApiResponse <long>(responseResult: clientId));
        }
예제 #27
0
        public async Task <string> SaveClient([FromBody] ClientRegistryDto client)
        {
            ClientsDto clients = await _clientService.GetClientsAsync(client.ClientName, 1, 1);

            if (clients.Clients.Count > 0)
            {
                throw new UserFriendlyErrorPageException($"客户端[{client.ClientId}]已经存在");
            }
            else
            {
                string    clientSecret = Guid.NewGuid().ToString("N").ToLower();
                ClientDto clientDto    = ToClientDto(client);
                int       clientId     = await _clientService.AddClientAsync(clientDto);

                await _clientService.AddClientSecretAsync(new ClientSecretsDto()
                {
                    Value       = clientSecret,
                    Description = clientSecret,
                    ClientId    = clientId
                });

                client.ClientSecret = clientSecret;

                foreach (var item in client.Properties)
                {
                    await _clientService.AddClientPropertyAsync(new ClientPropertiesDto()
                    {
                        Key        = item.Key,
                        Value      = item.Value,
                        ClientId   = clientId,
                        ClientName = client.ClientName
                    });
                }

                return(clientSecret);
            }
        }
예제 #28
0
 private ClientsDto GetResponse(IAppEntity app)
 {
     return(ClientsDto.FromApp(app, Resources));
 }
예제 #29
0
        public static ClientsDto ClientEntityToClientDto(ClientsEntity clientEntity)
        {
            ClientsDto clientDto = new ClientsDto(clientEntity.id, clientEntity.nombre, clientEntity.email, clientEntity.role);

            return(clientDto);
        }
예제 #30
0
        public IHttpActionResult AddClientDataBase(ClientsDto client)
        {
            try
            {
                if (client.ActualAddress == null)
                {
                    ModelState.AddModelError("addres", "Укажите адрес проживания");
                }

                if (client.CityFactResidenceID == 0)
                {
                    ModelState.AddModelError("City", "Укажите город проживания");
                }

                if (client.DateBirth == null)
                {
                    ModelState.AddModelError("DateBirth", "Укажите дату рождения");
                }

                if (client.CitizenshipID == 0)
                {
                    ModelState.AddModelError("Citizenship", "Укажите глаждаество");
                }

                if (client.SexID == 0)
                {
                    ModelState.AddModelError("Sex", "Введите под");
                }

                if (client.Name == null)
                {
                    ModelState.AddModelError("Name", "Введите имя");
                }

                if (client.MiddleName == null)
                {
                    ModelState.AddModelError("MiddleName", "Введите Отчество");
                }

                if (client.Surname == null)
                {
                    ModelState.AddModelError("Surname", "Введите Фамилию");
                }

                if (ModelState.IsValid)
                {
                    _bllFactory.UserBll.AddClientDataBase(client);
                }
                else
                {
                    return(BadRequest(ModelState));
                }


                return(Ok(true));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("error", ex.Message);
                return(BadRequest(ModelState));
            }
        }