コード例 #1
0
    public async Task <ActionResult <DtoPerson> > Add([FromBody] DtoPerson dtoPerson)
    {
        log.LogInformation("Adding person {dtoPerson}", dtoPerson);
        if (!ModelState.IsValid)
        {
            return(BadRequest(getModelStateErrorMessage()));
        }

        if (dtoPerson.ID != 0)
        {
            return(BadRequest("Cannot add with a valid id"));
        }

        if (string.IsNullOrEmpty(dtoPerson.AuthID))
        {
            var person = await personRepository.AddAsync(dtoPerson.Name, dtoPerson.Bio);

            return(mapper.Map <DtoPerson>(person));
        }
        else
        {
            var person = await personRepository.AddAsync(dtoPerson.Name, dtoPerson.Bio, dtoPerson.AuthID);

            return(mapper.Map <DtoPerson>(person));
        }
    }
コード例 #2
0
        public async Task AddAsync(PersonCreateModel person)
        {
            if (person.BirthDay == null || person.BirthDay > DateTime.Today)
            {
                throw new Exception("تاریخ تولد اجباری است و نمی تواند تاریخ آینده باشد");
            }

            if (string.IsNullOrWhiteSpace(person.Name))
            {
                throw new Exception("نام اجباری است");
            }

            if (string.IsNullOrWhiteSpace(person.Config))
            {
                throw new Exception("دسترسی اجباری است");
            }
            else
            {
                var permissions = JsonConvert.DeserializeObject <Permissions>(person.Config);
                if (permissions == null)
                {
                    throw new Exception("دسترسی معتبر نیست");
                }
            }
            await _personRepository.AddAsync(person);
        }
コード例 #3
0
        public async Task HandleAsync(CreatePerson command, ICorrelationContext context)
        {
            var customer = await _personRepository.GetAsync(command.Id);

            if (customer == null)
            {
                await _personRepository.AddAsync(new Person(command.Id, command.Email));

                await _busPublisher.PublishAsync(new PersonCreated(command.Id, customer.Email,
                                                                   command.FirstName, command.LastName, command.Address, command.Country), context);

                /*throw new CoursesManagementException("person_not_exist",
                 *  $"Customer account was not already created for user with id: '{command.Id}'.");*/
            }


            if (customer.Completed)
            {
                throw new CoursesManagementException("person_data_completed",
                                                     $"Customer account was already created for user with id: '{command.Id}'.");
            }

            customer.Complete(command.FirstName, command.LastName, command.Address, command.Country);
            await _personRepository.UpdateAsync(customer);

            await _busPublisher.PublishAsync(new PersonCreated(command.Id, customer.Email,
                                                               command.FirstName, command.LastName, command.Address, command.Country), context);
        }
コード例 #4
0
 public async Task <IActionResult> Add(Person person)
 {
     try {
         return(Ok(await _personRepository.AddAsync(_mapper.Map <Persons>(person))));
     } catch (Exception e) {
         return(BadRequest(e.Message));
     }
 }
コード例 #5
0
        public async Task <ActionResult> Create([FromBody] CreatePersonViewModel request)
        {
            var domainPerson = _mapper.Map <Person>(request);

            var validator = new CreatePersonViewModelValidator();
            await validator.ValidateAndThrowAsync(request);

            var createdPerson = await _personRepository.AddAsync(domainPerson);

            return(Ok(_mapper.Map <PersonViewModel>(createdPerson)));
        }
コード例 #6
0
        public async Task AddAsync(Person person)
        {
            // ToDo: Get the group details from the groupRepository
            var group = groupRepository.GetById(person.GroupId);

            // ToDo: Call faceAPIClient to create a new person. Do not forget to save APIPersonId
            person.APIPersonId = await faceAPIClient.PersonCreateAsync(group.Code, person.Fullname);

            // ToDo: Call personRepository to save the new person
            await personRepository.AddAsync(person);
        }
コード例 #7
0
        public async Task <IActionResult> Post(Person person)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            int id = await personRepository.AddAsync(person);

            return(CreatedAtAction(nameof(Get), id));
        }
コード例 #8
0
        public async Task <IActionResult> Create(Person model)
        {
            if (ModelState.IsValid)
            {
                bool isSuccessStatusCode = await repo.AddAsync(model);

                if (isSuccessStatusCode)
                {
                    return(RedirectToAction("index"));
                }
            }
            return(View());
        }
コード例 #9
0
        public async Task <IActionResult> Create([FromBody] PersonIndentifierModel dto)
        {
            if (dto == null)
            {
                return(BadRequest());
            }
            var person = _mapper.Map <Person>(dto);
            await _personRepository.AddAsync(person);

            await _personRepository.SaveChangesAsync();

            return(CreatedAtRoute("GetPerson", new { id = person.ID }, _mapper.Map <PersonIndentifierModel>(person)));
        }
コード例 #10
0
        public async Task AddAsync(Person person)
        {
            if (personRepository.Exists(person.Email))
            {
                throw new DuplicateEntryException("The email has been previously registered");
            }

            var group = groupRepository.GetById(person.GroupId);

            person.APIPersonId = await faceAPIClient.PersonCreateAsync(group.Code, person.Fullname);

            await personRepository.AddAsync(person);
        }
コード例 #11
0
        public async Task <IActionResult> Post([FromBody] Person person)
        {
            _logger.LogDebug("Post: {value}", person);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var personId = await _repository.AddAsync(person)
                           .ConfigureAwait(false);

            return(Created($"/api/people/{personId}", null));
        }
コード例 #12
0
        public async Task <IActionResult> Post([FromBody] Person person)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            person.Id = 0;
            await _repo.AddAsync(person);

            return(CreatedAtAction(nameof(Get), new
            {
                id = person.Id
            }, person));
        }
コード例 #13
0
        public async Task <IActionResult> Post([FromBody] Person model)
        {
            if (model == null)
            {
                return(BadRequest("Please provide a Person."));
            }
            if (string.IsNullOrEmpty(model.Email))
            {
                return(BadRequest("An email address is required."));
            }

            var entity = await repository.AddAsync(model);

            return(CreatedAtRoute(nameof(Get), entity.Id, entity));
        }
コード例 #14
0
        public async Task <Person> Create(CreatePersonCommand command)
        {
            var coffeePlaces = await GetCoffeePlaces(command.CoffeePlaceIds);

            var eventRooms = await GetEventRooms(command.EventRoomIds);

            command.AddCoffeePlaces(coffeePlaces);
            command.AddEventRooms(eventRooms);

            var eventRoom = new Person(command);

            await _personRepository
            .AddAsync(eventRoom);

            return(eventRoom);
        }
コード例 #15
0
        //
        // Summary:
        //     /// Method responsible for create registry. ///
        //
        // Parameters:
        //   command:
        //     The command param.
        //
        public async Task <Person> AddAsync(PersonCommand command)
        {
            _validationResult = await _personValidator.ValidateAsync(command);

            if (_validationResult.IsValid is false)
            {
                return(null);
            }

            Person person = new Person(command.Name, command.BirthDate, new Cpf(command.Cpf), command.Phone, new Email(command.Email), command.Profile, command.ProfessionalDescription);

            await _personRepository.AddAsync(person);

            await _entityAuditService.AddAsync("INS", nameof(Person), person);

            return(person);
        }
コード例 #16
0
        public async Task Assert_Add_Entity_Async_Is_Successful()
        {
            // Arrange
            var person = DataGenerator.GeneratePersons(1)[0];

            // Act
            await _personRepository.AddAsync(person);

            var affectedEntries = await _personRepository.CommitAsync();

            // Assert
            Assert.Equal(person.CountRelatedEntities() + 1, affectedEntries);
            Assert.False(person.Id == default);
            Assert.DoesNotContain(person.Vehicles, t => t.Id == default);
            Assert.DoesNotContain(person.Vehicles, t => t.ManufacturerId == default);
            Assert.DoesNotContain(person.Vehicles.SelectMany(t => t.Manufacturer.Subsidiaries), t => t.Id == default);
        }
コード例 #17
0
    public async Task <DtoPerson> GetAsync()
    {
        var emailAddress = User.Claims.Single(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value;

        try
        {
            var person = await personRepository.GetByAuthIdAsync(emailAddress);

            return(mapper.Map <DtoPerson>(person));
        }
        catch (NotFoundException <Person> )
        {
            var name   = User.Claims.Single(c => c.Type == "name").Value;
            var person = await personRepository.AddAsync(name, null, emailAddress);

            return(mapper.Map <DtoPerson>(person));
        }
    }
コード例 #18
0
ファイル: Add.cs プロジェクト: beardedbrainiac/SampleProject
            public async Task <PersonViewModel> Handle(Command request, CancellationToken cancellationToken)
            {
                try
                {
                    var person = await _persons.AddAsync(new Person
                    {
                        FirstName = request.FirstName,
                        LastName  = request.LastName,
                        Gender    = (Gender)int.Parse(request.Gender),
                        CreatedBy = request.GetUserName()
                    });

                    await _unitOfWork.Commit();

                    return(_mapper.Map <PersonViewModel>(person));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
コード例 #19
0
        public async Task Handle(AddPersonCommand notification)
        {
            var entityCurrent = Mapper.Map <PersonModel, Person>(notification.PersonModel);

            if (!IsEntityValid(entityCurrent))
            {
                return;
            }

            var personGroup = await _personRepository.GetPersonGroupByIdAsync(entityCurrent.PersonGroup.Id);

            if (personGroup == null)
            {
                NotifyErrorValidations("AddPersonCommand", "PersonGroup not found");
                return;
            }

            await _personRepository.AddAsync(entityCurrent);

            if (Commit())
            {
                await _mediator.PublishEvent(new PersonAddedEvent(_logger, Mapper.Map <PersonModel>(notification.PersonModel)));
            }
        }
コード例 #20
0
        //Basic

        public async Task <int> AddAsync(PersonEntity personEntity)
        {
            return(await _personRepository.AddAsync(personEntity));
        }
コード例 #21
0
        public async Task <IActionResult> CreatePerson([FromBody] Person person)
        {
            await _personRepository.AddAsync(person);

            return(Ok(person));
        }
コード例 #22
0
 public async Task HandleAsync(SignedUp @event, ICorrelationContext context)
 {
     var customer = new Person(@event.UserId, @event.Email);
     await _personRepository.AddAsync(customer);
 }
コード例 #23
0
        public override async Task <EntityOperationResult <PersonDto> > CreateAsync(PersonEditDto createDto)
        {
            string errors = CheckBeforeModification(createDto);

            if (!string.IsNullOrEmpty(errors))
            {
                return(EntityOperationResult <PersonDto> .Failure().AddError(errors));
            }

            try
            {
                var lstSkill    = createDto.Skills.Select(x => x.Name).Distinct().ToList();
                var skills      = new List <SkillDto>();
                var resultSkill = await skillOfLevelService.UpdateListSkillAsync(lstSkill);

                if (resultSkill.IsSuccess)
                {
                    skills.AddRange(resultSkill.Entities);
                }
                else
                {
                    return(EntityOperationResult <PersonDto> .Failure().AddError(resultSkill.GetErrorString()));
                }

                var skillOfLevels      = new List <SkillOfLevelEditDto>();
                var resultSkillOfLevel = await skillOfLevelService.UpdateListSkillOfLevelAsync(createDto.Skills, skills);

                if (resultSkillOfLevel.IsSuccess)
                {
                    skillOfLevels = mapper.Map <List <SkillOfLevelEditDto> >(resultSkillOfLevel.Entities);
                }
                else
                {
                    return(EntityOperationResult <PersonDto> .Failure().AddError(resultSkillOfLevel.GetErrorString()));
                }

                var person = new Person
                {
                    FirstName = createDto.FirstName,
                    SurName   = createDto.SurName,
                };
                var entity = await personRepository.AddAsync(person);

                await personRepository.SaveAsync();

                for (int i = 0; i < skillOfLevels.Count; i++)
                {
                    skillOfLevels[i].IsDelete = createDto.Skills.FirstOrDefault(x =>
                                                                                x.Name == skillOfLevels[i].Name &&
                                                                                x.StartLevel == skillOfLevels[i].StartLevel)?.IsDelete ?? false;
                }
                var resultSkillsOfPerson = await skillOfLevelService.UpdateListSkillOfPersonAsync(skillOfLevels, entity.Id);

                var dto = mapper.Map <PersonDto>(entity);

                return(EntityOperationResult <PersonDto> .Success(dto));
            }
            catch (Exception ex)
            {
                return(EntityOperationResult <PersonDto> .Failure().AddError(ex.Message));
            }
        }
コード例 #24
0
        public async Task <IActionResult> AddAsync(Person person)
        {
            await _personRepository.AddAsync(person);

            return(new CreatedAtActionResult("GetPerson", "Person", new { id = person.Id }, person));
        }
コード例 #25
0
 public async Task <PersonModel> CreatePerson(PersonModel model)
 {
     return(_personMapper.Map(await _personRepository.AddAsync(_personMapper.MapBack(model))));
 }
コード例 #26
0
 public async Task <PersonDTO> AddAsync(PersonDTO person)
 {
     return(mapper.Map <PersonDTO>(await personsRepository.AddAsync(mapper.Map <Person>(person))));
 }
コード例 #27
0
 public async Task RegisterNewPerson(Person p)
 {
     await personRepository.AddAsync(p);
 }
コード例 #28
0
 public async Task Handle(PersonCreateCommand notification, CancellationToken cancellationToken)
 {
     await _personRepository.AddAsync(_mapper.Map <Person>(notification));
 }
コード例 #29
0
 public Task <Response <PersonDto> > Handle(CreatePersonCommand request, CancellationToken cancellationToken)
 {
     return(_repository.AddAsync(request));
 }