Esempio n. 1
0
        public virtual async Task <IStatusResponse> DeleteAsync(
            DeletePersonRequest 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
            {
                context.Set <Person>().Remove(entity);
                context.Set <Address>().Remove(entity.Address);
                context.Set <Name>().Remove(entity.Name);

                await context.SaveChangesAsync(token);

                await eventDispatcher.DispatchAsync(new Events.DeleteEvent(entity));

                response = new StatusResponse(model.Id);
            }

            return(response);
        }
Esempio n. 2
0
        public void Exec(DeletePersonRequest request)
        {
            var hpme = _home.Single(h => h.People.Any(p => p.Id == request.PersonId));

            hpme.People.Remove(_people.Single(p => p.Id == request.PersonId));
            _people.Delete(request.PersonId);
            _db.SaveChanges();
        }
Esempio n. 3
0
        public async Task <IActionResult> Delete(Guid id)
        {
            DeletePersonRequest request = new DeletePersonRequest {
                Id = id
            };

            return(Ok(await _mediator.Send(new DeltePersonCommand(request))));
        }
Esempio n. 4
0
        public void WhenIDeleteTheLastAddedPerson()
        {
            var request = new DeletePersonRequest();

            request.PersonId = _container.GetInstance <IPersonListFeature>().Exec().Last().Id;
            var deleteFeature = _container.GetInstance <IDeletePersonFeature>();

            deleteFeature.Exec(request);
        }
        public virtual async Task <IStatusResponse> DeleteAsync(
            DeletePersonRequest model, CancellationToken token = default)
        {
            model.ArgumentNullCheck(nameof(model));

            using (var scope = TransactionFactory.CreateTransaction())
            {
                var result = await service.DeleteAsync(model, token);

                scope.Complete();

                return(result);
            }
        }
        /// <summary>
        /// 删除人员。
        /// </summary>
        /// <param name="req"><see cref="DeletePersonRequest"/></param>
        /// <returns><see cref="DeletePersonResponse"/></returns>
        public DeletePersonResponse DeletePersonSync(DeletePersonRequest req)
        {
            JsonResponseModel <DeletePersonResponse> rsp = null;

            try
            {
                var strResp = this.InternalRequestSync(req, "DeletePerson");
                rsp = JsonConvert.DeserializeObject <JsonResponseModel <DeletePersonResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
Esempio n. 7
0
        /// <summary>
        /// Удаляет данные персоны асинхронно
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <DeletePersonResponse> DeleteAsync(DeletePersonRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("Person model DeletePersonRequest  is invalid");
            }
            var resp = new DeletePersonResponse();

            try
            {
                var unit = factory.CreateUnitOfWork();
                unit.Persons.Delete(request.Id);
                await unit.SaveAsync();
            }
            catch (Exception e) { resp.AddMessage(new Contracts.Message(e.Message)); }
            return(resp);
        }
Esempio n. 8
0
        /// <summary>
        /// Удаляет файл биографии персоны
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public DeletePersonResponse DeleteBiography(DeletePersonRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("Person model DeletePersonRequest  is invalid");
            }
            var resp = new DeletePersonResponse();

            try
            {
                var unit   = factory.CreateUnitOfWork();
                var person = unit.Persons.GetItem(request.Id);
                person.Biography = null;
                unit.Persons.Update(person);
                unit.Save();
            }
            catch (Exception e) { resp.AddMessage(new Contracts.Message(e.Message)); }
            return(resp);
        }
        public DeletePersonResponse DeletePerson(DeletePersonRequest request)
        {
            try
            {
                var relatedPersons = _db.RelatedPersons.Where(t => t.PersonId == request.PersonId || t.RelatedPersonId == request.PersonId).ToList();
                if (relatedPersons.Count == 0)
                {
                    return(Fail(new DeletePersonResponse(), RsStrings.PersonNotFound));
                }
                else
                {
                    _db.RelatedPersons.RemoveRange(relatedPersons);
                    _db.SaveChanges();
                }

                return(Success(new DeletePersonResponse()));
            }
            catch (Exception ex)
            {
                return(Error(new DeletePersonResponse(), RsStrings.DeletePersonUnexpectedException));
            }
        }
Esempio n. 10
0
        public async Task <PersonResponse> DeletePersonAsync(DeletePersonRequest request)
        {
            if (request?.Id == null)
            {
                throw new ArgumentNullException();
            }

            Person result = await _personRespository.GetAsync(request.Id);

            if (result == null)
            {
                throw new ArgumentException($"Entity with {request.Id} is not present");
            }

            result.IsInactive = true;

            _personRespository.Update(result);
            int modifiedRecords = await _personRespository.UnitOfWork.SaveChangesAsync();

            _logger.LogInformation(Logging.Events.Delete, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords);

            return(_personMapper.Map(result));
        }
Esempio n. 11
0
 public ActionResult <DeletePersonResponse> DeletePerson([FromBody] DeletePersonRequest request)
 {
     return(_personService.DeletePerson(request));
 }
Esempio n. 12
0
        public async Task <IActionResult> Delete([Required] DeletePersonRequest model, CancellationToken token)
        {
            var result = await service.DeleteAsync(model, token);

            return(GenerateResponse(result));
        }