public async Task UpdatePersonAsync(UpdatePersonRequest updatePersonRequest, int personId) { await using var connection = new SqlConnection(_dbConfig.ConnectionString); await using var command = new SqlCommand("UpdatePerson", connection) { CommandType = CommandType.StoredProcedure }; await connection.OpenAsync(); command.Parameters.AddWithValue("personId", personId); if (updatePersonRequest.Name != null) { command.Parameters.AddWithValue("name", updatePersonRequest.Name); } if (updatePersonRequest.SecondName != null) { command.Parameters.AddWithValue("secondName", updatePersonRequest.SecondName); } if (updatePersonRequest.Surname != null) { command.Parameters.AddWithValue("surname", updatePersonRequest.Surname); } if (updatePersonRequest.DOB != null) { command.Parameters.AddWithValue("dob", updatePersonRequest.DOB); } await command.ExecuteNonQueryAsync(); }
public async Task <ZqSignResponseBase> UpdatePersonAsync(UpdatePersonRequest request) { const string path = "personUpdate"; var response = await GetResponseAsync <ZqSignResponseBase, UpdatePersonRequest>(path, request); return(response); }
public async Task <ActionResult> Put(Guid id, [FromBody] UpdatePersonModel model) { var request = new UpdatePersonRequest(id, model.NameConst, model.PrimaryName, model.BirthYear, model.DeathYear); var response = await _mediator.Send(request); return(Ok(response)); }
public virtual async Task <IStatusResponse> UpdateAsync( UpdatePersonRequest model, CancellationToken token = default) { model.ArgumentNullCheck(nameof(model)); var entity = await store.GetEntityAsync(model.Id, token); IStatusResponse response; if (entity == null) { response = NotFoundStatusResponse(model.Id); } else { model.UpdateEntity(entity); await context.SaveChangesAsync(token); await eventDispatcher.DispatchAsync(new Events.UpdateEvent(entity)); response = new StatusResponse(model.Id); } return(response); }
public async Task <UpdatePersonPayload> UpdatePersonAsync( UpdatePersonRequest input, CancellationToken cancellationToken) { Person person = await _personService.UpdatePersonAsync(input, cancellationToken); return(new UpdatePersonPayload(person)); }
public void UpdatePersonReturns200WhenSuccessful() { var request = new UpdatePersonRequest(); var result = _residentController.UpdatePerson(request) as ObjectResult; result?.StatusCode.Should().Be(204); }
/// <summary> /// Update Person. /// </summary> /// <param name="id"></param> /// <param name="payload"></param> /// <returns></returns> public async Task <Person> UpdatePerson(string id, UpdatePersonRequest payload) { Contract.Requires <ArgumentNullException>(id != null); Contract.Requires <ArgumentNullException>(payload != null); using (var request = CreateMessage(HttpMethod.Put, Uri.Combine("person").Combine(id), payload)) return(await SendAsync <Person>(request)); }
public Task UpdatePerson(UpdatePersonRequest request) { var param = new ParamBuilder() .WithPersonId(request.Id) .WithParam("Email", request.Email) .WithParam("Phone", request.Phone) .WithParam("FavouriteDrinkId", request.FavouriteDrinkId); return(db.Update(param)); }
public void ValidationFailsIfPersonIdIsNotBiggerThan0() { UpdatePersonRequest request = GetValidRequest(); request.Id = 0; var errors = ValidationHelper.ValidateModel(request); Assert.AreEqual(errors.Count, 1); Assert.IsTrue(errors.Any(x => x.ErrorMessage.Contains("Please enter valid person id"))); }
public async Task <Response> Handle(UpdateFavouriteDrink command) { var request = new UpdatePersonRequest() { Id = command.Id, FavouriteDrinkId = command.FavouriteDrinkId }; await _dataProvider.UpdatePerson(request); return(SuccessHandler.ReturnUpdateSuccess(EntityName)); }
public IActionResult UpdatePerson([FromBody] UpdatePersonRequest request) { try { _residentUseCase.UpdateResident(request); return(StatusCode(204)); } catch (UpdatePersonException ex) { return(NotFound(ex.Message)); } }
public async Task <Response> Handle(UpdateEmail command) { var request = new UpdatePersonRequest() { Id = command.Id, Email = command.Email }; await _dataProvider.UpdatePerson(request); return(SuccessHandler.ReturnUpdateSuccess(EntityName)); }
public void UpdatePersonReturns404WhenPersonNotFound() { var request = new UpdatePersonRequest(); _mockResidentUseCase .Setup(x => x.UpdateResident(request)) .Throws(new UpdatePersonException("Person not found")); var result = _residentController.UpdatePerson(request) as ObjectResult; result?.StatusCode.Should().Be(404); result?.Value.Should().Be("Person not found"); }
public virtual async Task <IStatusResponse> UpdateAsync( UpdatePersonRequest model, CancellationToken token = default) { model.ArgumentNullCheck(nameof(model)); using (var scope = TransactionFactory.CreateTransaction()) { var result = await service.UpdateAsync(model, token); scope.Complete(); return(result); } }
public async Task UpdatePersonTest() { var request = new UpdatePersonRequest { UserCode = "2018091316200001", Name = "刺猬头", Mobile = "15867865485", IdCardNo = "321111198602212564" }; var response = await Service.UpdatePersonAsync(request); Assert.NotNull(response); Assert.Equal(ErrorCode.Success, response.Code); }
public async Task UpdatePersonNotExistedTest() { var request = new UpdatePersonRequest { UserCode = DateTime.Now.ToFileTimeUtc().ToString(), Name = "刺猬头", Mobile = "15867865485", IdCardNo = "321111198602212564" }; var response = await Service.UpdatePersonAsync(request); Assert.NotNull(response); Assert.Equal(ErrorCode.UserCodeNotExisted, response.Code); }
public async Task <ApiResponse> Put(long id, [FromBody] UpdatePersonRequest dto) { //if (ModelState.IsValid) //{ // var person = _mapper.Map<Person>(dto); // person.ID = id; // if (await _personManager.UpdateAsync(person)) // return new ApiResponse($"Record with Id: {id} sucessfully updated.", true); // else // throw new ApiException($"Record with Id: {id} does not exist.", Status404NotFound); //} //else throw new ApiException(ModelState.AllErrors()); }
public async Task <Person> CreatePersonAsync(UpdatePersonRequest person) { var dbPerson = _mapper.Map <UpdatePersonRequest, DbPerson>(person); var source = await _repo.AddAsync(dbPerson); var result = _mapper.Map <DbPerson, Person>(source); // Не уверен, верно ли вносить в кэш данные на этом уровне или же лучше на уровне репозитория? if (result != null) { _cache.Set(result.Id, result, new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(15) }); } return(result); }
/// <summary> /// Обновляет данные персоны асинхронно /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <UpdatePersonResponse> UpdateAsync(UpdatePersonRequest request) { if (request == null) { throw new ArgumentNullException("Person model UpdatePersonRequest is invalid"); } var resp = new UpdatePersonResponse(); try { var unit = factory.CreateUnitOfWork(); var item = mapper.Map <Entities.Person>(request.Person); unit.Persons.Update(item); await unit.SaveAsync(); } catch (Exception e) { resp.AddMessage(new Contracts.Message(e.Message)); } return(resp); }
public PersonModel UpdatePerson(long id, [FromBody] UpdatePersonRequest request) { var data = new PersonData() { Name = request.Name, Gender = request.Gender, Email = request.Email, Phone = request.Phone, DateBirth = request.DateBirth, DateDeath = request.DateDeath }; if (!String.IsNullOrWhiteSpace(request.Avatar)) { _manager.ChangePersonAvatar(id, request.Avatar); } return(_manager.UpdatePerson(id, data).ToSerial()); }
public async Task <ApiResponse> Put(int id, [FromBody] UpdatePersonRequest dto) { if (ModelState.IsValid) { var person = _mapper.Map <Person>(dto); person.Id = id; if (await _personManager.UpdateAsync(person)) { return(new ApiResponse($"Record with Id: {id} sucessfully updated.", true)); } else { throw new ApiException($"Record with Id: {id} does not exist.", Status404NotFound); } } else { throw new ApiException(ModelState.AllErrors()); } }
public async Task <ApiResponse> Put(long id, [FromBody] UpdatePersonRequest updateRequest) { if (!ModelState.IsValid) { throw new ApiProblemDetailsException(ModelState); } var person = _mapper.Map <Person>(updateRequest); person.Id = id; if (await _personManager.UpdateAsync(person)) { return(new ApiResponse($"Record with Id: {id} sucessfully updated.", true)); } else { throw new ApiProblemDetailsException($"Record with Id: {id} does not exist.", Status404NotFound); } }
public async Task <ActionResult <PersonResponse> > Update(Guid id, UpdatePersonRequest updatePersonRequest) { try { var person = _mapper.Map <Person>(updatePersonRequest); person = await _personService.SaveAsync(person); var result = _mapper.Map <PersonResponse>(person); return(Ok(result)); } catch (Exception ex) { var error = (new CustomBadRequest { ErrorCode = StatusCodes.Status400BadRequest, ErrorMessage = ex.ToString(), }); _logger.LogError(ex, "Exception Caught. PersonController.Update method."); return(BadRequest(error)); } }
public void Exec(UpdatePersonRequest request) { request.FillEntity(_people.ById(request.Id)); _db.SaveChanges(); }
public async Task <UpdatePersonResponse> Put(int id, [FromBody] UpdatePersonRequest request) { return(await new PersonModel(factory, mapper).UpdateAsync(request)); }
public async Task UpdatePersonAsync(UpdatePersonRequest updatePersonRequest, int personId) { await userRepository.UpdatePersonAsync(updatePersonRequest, personId); }
public async Task<UpdatePersonResponse> Put(int id, [FromBody] UpdatePersonRequest request) { return await personService.UpdateAsync(request); }
public async Task<UpdatePersonResponse> Post([FromBody] UpdatePersonRequest request) { return await personService.CreateAsync(request); }
public void UpdatePerson(UpdatePersonRequest request) { Person person = _databaseContext .Persons .Include(x => x.Addresses) .Include(x => x.PhoneNumbers) .Include(x => x.OtherNames) .FirstOrDefault(x => x.Id == request.Id); if (person == null) { throw new UpdatePersonException("Person not found"); } person.AgeContext = request.ContextFlag; person.DateOfBirth = request.DateOfBirth; person.DateOfDeath = request.DateOfDeath; person.EmailAddress = request.EmailAddress; person.Ethnicity = request.Ethnicity; person.FirstLanguage = request.FirstLanguage; person.FirstName = request.FirstName; person.FullName = $"{request.FirstName} {request.LastName}"; person.Gender = request.Gender; person.LastModifiedBy = request.CreatedBy; person.LastName = request.LastName; person.NhsNumber = request.NhsNumber; person.PreferredMethodOfContact = request.PreferredMethodOfContact; person.Religion = request.Religion; person.Restricted = request.Restricted; person.SexualOrientation = request.SexualOrientation; person.Title = request.Title; //replace phone numbers _databaseContext.PhoneNumbers.RemoveRange(person.PhoneNumbers); if (request.PhoneNumbers != null) { foreach (var number in request.PhoneNumbers) { person.PhoneNumbers.Add(number.ToEntity(person.Id, request.CreatedBy)); } } //replace other names _databaseContext.PersonOtherNames.RemoveRange(person.OtherNames); if (request.OtherNames != null) { foreach (var otherName in request.OtherNames) { person.OtherNames.Add(otherName.ToEntity(person.Id, request.CreatedBy)); } } //check for changed address if (request.Address != null) { Address displayAddress = person.Addresses.FirstOrDefault(x => x.IsDisplayAddress == "Y"); if (displayAddress == null) { person.Addresses.Add(GetNewDisplayAddress(request.Address.Address, request.Address.Postcode, request.Address.Uprn, request.CreatedBy)); } else { //has address changed? if (!(request.Address.Address == displayAddress.AddressLines && request.Address.Postcode == displayAddress.PostCode && displayAddress.Uprn == request.Address.Uprn)) { displayAddress.IsDisplayAddress = "N"; displayAddress.EndDate = DateTime.Now; displayAddress.LastModifiedBy = request.CreatedBy; person.Addresses.Add(GetNewDisplayAddress(request.Address.Address, request.Address.Postcode, request.Address.Uprn, request.CreatedBy)); } } } else //address not provided, remove current display address if it exists { Address displayAddress = person.Addresses.FirstOrDefault(x => x.IsDisplayAddress == "Y"); if (displayAddress != null) { displayAddress.IsDisplayAddress = "N"; displayAddress.EndDate = DateTime.Now; displayAddress.LastModifiedBy = request.CreatedBy; } } DateTime dt = DateTime.Now; UpdatePersonCaseNote note = new UpdatePersonCaseNote() { FirstName = person.FirstName, LastName = person.LastName, MosaicId = person.Id.ToString(), Timestamp = dt.ToString("dd/MM/yyyy H:mm:ss"), //in line with imported form data WorkerEmail = request.CreatedBy, Note = $"{dt.ToShortDateString()} Person details updated - by {request.CreatedBy}.", FormNameOverall = "API_Update_Person", FormName = "Person updated", CreatedBy = request.CreatedBy }; CaseNotesDocument caseNotesDocument = new CaseNotesDocument() { CaseFormData = JsonConvert.SerializeObject(note) }; //TODO: refactor so gateways don't call each other _ = _processDataGateway.InsertCaseNoteDocument(caseNotesDocument).Result; _databaseContext.SaveChanges(); }
public async Task <IActionResult> UpdatePerson(UpdatePersonRequest updatePersonRequest, int personId) { await _userService.UpdatePersonAsync(updatePersonRequest, personId); return(Ok(HttpStatusCode.OK)); }