public void UpdateClient(Guid clientId, string propertyName, object value, Action <ResponseBase> callback)
 {
     Task.Factory.StartNew(() => {
         Guid messageId = Guid.NewGuid();
         try {
             UpdateClientRequest request = new UpdateClientRequest {
                 MessageId    = messageId,
                 LoginName    = LoginName,
                 ClientId     = clientId,
                 PropertyName = propertyName,
                 Value        = value,
                 Timestamp    = DateTime.Now
             };
             request.SignIt(Password);
             using (var service = CreateService()) {
                 ResponseBase response = service.UpdateClient(request);
                 callback?.Invoke(response);
             }
         }
         catch (CommunicationException e) {
             Global.DebugLine(e.Message, ConsoleColor.Red);
             callback?.Invoke(ResponseBase.ClientError(messageId, e.Message));
         }
         catch (Exception e) {
             Global.Logger.Error(e.Message, e);
             callback?.Invoke(ResponseBase.ClientError(messageId, e.Message));
         }
     });
 }
Ejemplo n.º 2
0
        public async Task UpdateClient(Boolean mediatorResult)
        {
            Random random = new Random();
            Guid   id     = random.NextGuid();

            var request = new UpdateClientRequest
            {
            };

            var mediatorMock = new Mock <IMediator>(MockBehavior.Strict);

            mediatorMock.Setup(x => x.Send(It.Is <UpdateClientCommand>(y =>
                                                                       y.Request == request && y.Request.SystemId == id), It.IsAny <CancellationToken>())).ReturnsAsync(mediatorResult).Verifiable();

            var controller = new ClientController(
                mediatorMock.Object,
                Mock.Of <IClientRepository>(MockBehavior.Strict),
                Mock.Of <ILogger <ClientController> >()
                );

            var actionResult = await controller.UpdateClient(id, request);

            if (mediatorResult == true)
            {
                actionResult.EnsureNoContentResult();
            }
            else
            {
                actionResult.EnsureBadRequestObjectResult("unable to complete service operation");
            }

            mediatorMock.Verify();
        }
        private async Task SaveClick()
        {
            if (ToSave.ClientId == 0)
            {
                var toCreate = new CreateClientRequest()
                {
                    FullName          = ToSave.FullName,
                    EmailAddress      = ToSave.EmailAddress,
                    Salutation        = ToSave.Salutation,
                    PreferredDoctorId = ToSave.PreferredDoctorId,
                    PreferredName     = ToSave.PreferredName,
                };
                await ClientService.CreateAsync(toCreate);
            }
            else
            {
                var toUpdate = new UpdateClientRequest()
                {
                    ClientId          = ToSave.ClientId,
                    FullName          = ToSave.FullName,
                    EmailAddress      = ToSave.EmailAddress,
                    Salutation        = ToSave.Salutation,
                    PreferredDoctorId = ToSave.PreferredDoctorId,
                    PreferredName     = ToSave.PreferredName,
                };

                await ClientService.EditAsync(toUpdate);
            }

            CancelClick();
            await ReloadData();
        }
Ejemplo n.º 4
0
        public ActionResult <int> Put(
            [FromRoute] int id,
            [FromBody] UpdateClientRequest clientRequest)
        {
            if (!ModelState.IsValid || id != clientRequest.Id)
            {
                return(BadRequest());
            }

            var client = mockClients.GetById(id);

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

            client.Name   = clientRequest.Name;
            client.Email  = clientRequest.Email;
            client.Gender = clientRequest.Gender;
            client.Phone  = clientRequest.Phone;

            mockClients.Update(client);

            return(Ok(new { client.Id }));
        }
Ejemplo n.º 5
0
        static void ExecuteJson()
        {
            var client = new JsonServiceClient("http://*****:*****@email.com"
            };
            ClientResponse response = client.Post <ClientResponse>(createRequest);

            var updateRequest = new UpdateClientRequest
            {
                Email = "*****@*****.**",
                Id    = response.Id
            };

            response = client.Put <ClientResponse>(updateRequest);

            var getClientRequest = new GetClientRequest
            {
                Id = response.Id
            };

            response = client.Get <ClientResponse>(getClientRequest);

            var deleteRequest = new DeleteClientRequest
            {
                Id = response.Id
            };

            client.Delete(deleteRequest);
        }
Ejemplo n.º 6
0
        static void ExecuteSoap()
        {
            var client = new SoapServiceClient("NeliburSoapService");

            var createRequest = new CreateClientRequest
            {
                Email = "*****@*****.**"
            };
            ClientResponse response = client.Post <ClientResponse>(createRequest);

            var updateRequest = new UpdateClientRequest
            {
                Email = "*****@*****.**",
                Id    = response.Id
            };

            response = client.Put <ClientResponse>(updateRequest);

            var getClientRequest = new GetClientRequest
            {
                Id = response.Id
            };

            response = client.Get <ClientResponse>(getClientRequest);

            var deleteRequest = new DeleteClientRequest
            {
                Id = response.Id
            };

            client.Delete(deleteRequest);
        }
Ejemplo n.º 7
0
        public void Update(Client client)
        {
            var request = new UpdateClientRequest();

            request.Client = client;
            var response = HttpPost <UpdateClientRequest>("api/client/update", request, MediaType.Json);
        }
 public ResponseBase UpdateClient(UpdateClientRequest request)
 {
     if (request == null)
     {
         return(LoadClientResponse.InvalidInput(Guid.Empty, "参数错误"));
     }
     try {
         if (string.IsNullOrEmpty(request.LoginName))
         {
             return(ResponseBase.InvalidInput(request.MessageId, "登录名不能为空"));
         }
         if (!HostRoot.Current.UserSet.TryGetKey(request.LoginName, out IUser key))
         {
             return(ResponseBase.Forbidden(request.MessageId));
         }
         if (!request.Timestamp.IsInTime())
         {
             return(ResponseBase.Expired(request.MessageId));
         }
         if (request.Sign != request.GetSign(key.Password))
         {
             return(ResponseBase.Forbidden(request.MessageId, "签名验证未通过"));
         }
         HostRoot.Current.ClientSet.UpdateClient(request.ClientId, request.PropertyName, request.Value);
         return(ResponseBase.Ok(request.MessageId));
     }
     catch (Exception e) {
         Global.Logger.ErrorDebugLine(e.Message, e);
         return(ResponseBase.ServerError(request.MessageId, e.Message));
     }
 }
Ejemplo n.º 9
0
        public BaseResponse UpdateClient(UpdateClientRequest request)
        {
            return(ServiceProcessor.ProcessRequest(request,
                                                   //inbound.do validate or do something here
                                                   () =>
            {
            },

                                                   req =>
            {
                var response = new BaseResponse();
                using (var repo = new NhRepository <Client>())
                {
                    var entity = repo.GetById(req.Id);
                    if (entity == null)
                    {
                        throw new EeException(ErrorCodes.NotFound, "Object is not found.");
                    }

                    entity.Name = req.Name;
                    //TODO:

                    repo.Update(entity);
                }
                return response;
            }
                                                   ));
        }
Ejemplo n.º 10
0
 public IActionResult Update(int id, UpdateClientRequest updateClientRequest)
 {
     _authenticationService.IsAuthorized(Request, "EMPLOYEE");
     validateModel();
     _clientsService.Update(id, updateClientRequest);
     return(NoContent());
 }
Ejemplo n.º 11
0
        public async Task <int> UpdateClient(UpdateClientRequest request)
        {
            Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction transaction = _db.Database.BeginTransaction();
            ClientEntity client = await _db.Client.FindAsync(request.Id);

            if (client == null)
            {
                throw new ClientNotFoundException(request.Id);
            }
            await _db.Client.Where(a => a.Id == request.Id).UpdateAsync(c => new ClientEntity
            {
                FirstName      = request.FirstName,
                LastName       = request.LastName,
                SexId          = (byte)request.Sex,
                PersonalNumber = request.PersonalNumber,
                BirthDate      = request.BirthDate,
                BirthCity      = request.City,
                PhotoUrl       = request.PhotoAddress,
            });

            if (request.PhoneNumbers.Any())
            {
                await _db.ClientPhoneNumber.Where(c => c.ClientId == client.Id && !request.PhoneNumbers.Select(p => (byte)p.Type).Contains(c.TypeId)).DeleteAsync();
            }
            await _db.BulkMergeAsync(request.PhoneNumbers.Select(x => new ClientPhoneNumberEntity {
                ClientId = request.Id, TypeId = (byte)x.Type, Phone = x.Phone
            }), o => o.ColumnPrimaryKeyExpression = c => new { c.ClientId, c.TypeId });

            await transaction.CommitAsync();

            return(client.Id);
        }
Ejemplo n.º 12
0
 public void UpdateClientAsync(string objectId, string propertyName, object value, Action<ResponseBase, Exception> callback) {
     UpdateClientRequest request = new UpdateClientRequest {
         ObjectId = objectId,
         PropertyName = propertyName,
         Value = value
     };
     JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IClientDataController.UpdateClient), data: request, callback);
 }
Ejemplo n.º 13
0
 public int EnableAccess(UpdateClientRequest request)
 {
     return(Repository.Prowatch.ExecuteNonQuery("LNF.dbo.ClientUpdate", new Dictionary <string, object>
     {
         ["Action"] = "EnableAccess",
         ["ClientID"] = request.ClientID,
         ["ExpireOn"] = Utility.DBNullIf(request.ExpireOn)
     }, CommandType.StoredProcedure));
 }
Ejemplo n.º 14
0
        public object Put(UpdateClientRequest request)
        {
            Client client = _clients.Single(x => x.Id == request.Id);

            client.Email = request.Email;
            return(new ClientResponse {
                Id = client.Id, Email = client.Email
            });
        }
        public async Task <RegisteredClient> Handle(UpdateClientRequest request, CancellationToken cancellationToken)
        {
            var client = request.ToEntity();

            this._dbContext.Clients.Attach(client).State = EntityState.Modified;
            await this._dbContext.SaveChangesAsync();

            return(client.ToDTO());
        }
Ejemplo n.º 16
0
        public void UpdateClientAsync(string objectId, string propertyName, object value, Action <ResponseBase, Exception> callback)
        {
            UpdateClientRequest request = new UpdateClientRequest {
                ObjectId     = objectId,
                PropertyName = propertyName,
                Value        = value
            };

            RpcRoot.PostAsync(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IClientController.UpdateClient), request, request, callback);
        }
            public void UpdateClientAsync(string objectId, string propertyName, object value, Action <ResponseBase, Exception> callback)
            {
                UpdateClientRequest request = new UpdateClientRequest {
                    ObjectId     = objectId,
                    PropertyName = propertyName,
                    Value        = value
                };

                PostAsync(SControllerName, nameof(IControlCenterController.UpdateClient), request.ToQuery(SingleUser.LoginName, SingleUser.PasswordSha1), request, callback);
            }
Ejemplo n.º 18
0
        public object Put(UpdateClientRequest request)
        {
            Console.WriteLine("Put Request: {0}", request);
            Client client = _clients.Single(x => x.Id == request.Id);

            client.Email = request.Email;
            return(new ClientResponse {
                Id = client.Id, Email = client.Email
            });
        }
Ejemplo n.º 19
0
        public async Task <IHttpActionResult> UpdateClient([FromUri] int update, [FromBody] UpdateClientRequest updateRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _clientService.UpdateClientAsync(update, updateRequest);

            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
        }
Ejemplo n.º 20
0
        public HttpResponseMessage UpdateClient(UpdateClientRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            SuccessResponse response = new SuccessResponse();

            ClientsService.UpdateClient(model);
            return(Request.CreateResponse(response));
        }
Ejemplo n.º 21
0
        private static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
            //                        PerformanceTest();

            var client = new JsonServiceClient(Settings.Default.ServiceAddress);

            var createRequest = new CreateClientRequest
            {
                Email = "*****@*****.**"
            };
            var response = client.Post <ClientResponse>(createRequest);

            Console.WriteLine("POST Response: {0}\n", response);

            var updateRequest = new UpdateClientRequest
            {
                Email = "*****@*****.**",
                Id    = response.Id
            };

            response = client.Put <ClientResponse>(updateRequest);
            Console.WriteLine("PUT Response: {0}\n", response);

            var getClientRequest = new GetClientRequest
            {
                Id   = response.Id,
                Date = DateTime.Now.Date
            };

            response = client.Get <ClientResponse>(getClientRequest);
            Console.WriteLine("GET Response: {0}\n", response);

            var deleteRequest = new DeleteClientRequest
            {
                Id = response.Id
            };

            client.Delete(deleteRequest);

            var certificate = new MemoryStream(File.ReadAllBytes("Certificate.cer"));

            var uploadRequest = new UploadRequest
            {
                FileContents     = certificate.ToArray(),
                OriginalFileName = "MyFileName.cert",
                UploaderId       = Guid.NewGuid().ToString()
            };

            client.Post(uploadRequest);

            Console.ReadKey();
        }
Ejemplo n.º 22
0
        public async Task <IHttpActionResult> AddClient([FromBody] UpdateClientRequest createRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var client = await _clientService.CreateClientAsync(createRequest);

            var location = string.Format("/api/clients/{0}", client.OrderId);

            return(Created <Client>(location, client));
        }
Ejemplo n.º 23
0
 public static Client ToEntity(this UpdateClientRequest request)
 {
     return(new Client
     {
         Id = request.Id,
         Address = request.Address,
         DNI = request.DNI,
         Email = request.Email,
         LastNames = request.LastNames,
         Names = request.Names,
         Phone = request.Phone
     });
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Clients / Update Client
        /// </summary>
        /// <param name="clientId">Client ID</param>
        public async Task <UpdateClientResponse> UpdateClientAsync(UpdateClientRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("Value cannot be null.", nameof(request));
            }
            if (string.IsNullOrEmpty(request.Name))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(request.Name));
            }

            return(await ExecuteAsync <UpdateClientResponse>(UpdateRequest <UpdateClientRequest>(CLIENTS_PATH, request.Id, request)).ConfigureAwait(false));
        }
Ejemplo n.º 25
0
        public async Task <bool> UpdateAsync(string clientId, UpdateClientRequest request, CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentNullException(nameof(clientId));
            }
            cancellationToken.ThrowIfCancellationRequested();
            await _client.SetAuthHeaderAsync(cancellationToken);

            var content = JsonSerializer.Serialize(request, _client.Options);
            var results = await _client.HttpClient.PatchAsync($"api/v2/clients/{clientId}", new StringContent(content, Encoding.UTF8, "application/json"), cancellationToken);

            return(results.IsSuccessStatusCode);
        }
Ejemplo n.º 26
0
        public UpdateClientRequest GetUpdateUserDateRequest(ClientProfile client, Role role, int teamId, int userId, ClientProfile oldClientProfile)
        {
            var request = new UpdateClientRequest
            {
                Client           = client,
                Role             = role,
                TeamId           = teamId,
                UserId           = userId,
                OldClientProfile = oldClientProfile,
                ActionType       = DataBaseCommunication.Mappers.Requests.ActionType.Update
            };

            return(request);
        }
Ejemplo n.º 27
0
        private async void UpdateClient()
        {
            UpdateClientRequest updateClientRequest = new UpdateClientRequest
            {
                FirstName   = tbIme.Text,
                LastName    = tbPrezime.Text,
                Email       = tbEmail.Text,
                Address     = tbAdresa.Text,
                PhoneNumber = tbTelefon.Text,
                Password    = tbPassword.Text,
                Status      = fromString(cbStatus.Text)
            };

            await _apiService.Update <Client>(_clientForEdit.Id, updateClientRequest);
        }
Ejemplo n.º 28
0
        public async Task<ActionResult> Put([FromBody] UpdateClientRequest updateClientRequest)
        {
            if (updateClientRequest == null)
            {
                return BuildError(ErrorCodes.InvalidRequestCode, "no parameter in body request", HttpStatusCode.BadRequest);
            }

            if (!await _clientActions.UpdateClient(updateClientRequest.ToParameter()))
            {
                return new StatusCodeResult(StatusCodes.Status500InternalServerError);
            }

            await _representationManager.AddOrUpdateRepresentationAsync(this, GetClientStoreName + updateClientRequest.ClientId, false);
            await _representationManager.AddOrUpdateRepresentationAsync(this, GetClientsStoreName, false);
            return new NoContentResult();
        }
        public async Task <BaseResponse> ExecuteAsync(Uri clientsUri, UpdateClientRequest client, string authorizationHeaderValue = null)
        {
            if (clientsUri == null)
            {
                throw new ArgumentNullException(nameof(clientsUri));
            }

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var httpClient     = _httpClientFactory.GetHttpClient();
            var serializedJson = JsonConvert.SerializeObject(client).ToString();
            var body           = new StringContent(serializedJson, Encoding.UTF8, "application/json");
            var request        = new HttpRequestMessage
            {
                Method     = HttpMethod.Put,
                RequestUri = clientsUri,
                Content    = body
            };

            if (!string.IsNullOrWhiteSpace(authorizationHeaderValue))
            {
                request.Headers.Add("Authorization", "Bearer " + authorizationHeaderValue);
            }

            var httpResult = await httpClient.SendAsync(request);

            var content = await httpResult.Content.ReadAsStringAsync().ConfigureAwait(false);

            try
            {
                httpResult.EnsureSuccessStatusCode();
            }
            catch (Exception)
            {
                return(new BaseResponse
                {
                    ContainsError = true,
                    Error = JsonConvert.DeserializeObject <ErrorResponse>(content),
                    HttpStatus = httpResult.StatusCode
                });
            }

            return(new BaseResponse());
        }
Ejemplo n.º 30
0
        public async Task <ActionResult> Put([FromBody] UpdateClientRequest updateClientRequest)
        {
            if (updateClientRequest == null)
            {
                throw new ArgumentNullException(nameof(updateClientRequest));
            }

            if (!await _clientActions.UpdateClient(updateClientRequest.ToParameter()))
            {
                return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
            }

            await _representationManager.AddOrUpdateRepresentationAsync(this, GetClientStoreName + updateClientRequest.ClientId, false);

            await _representationManager.AddOrUpdateRepresentationAsync(this, GetClientsStoreName, false);

            return(new NoContentResult());
        }
 public void Put(UpdateClientRequest request)
 {
     Repository.Update(request.Entity);
 }