public IHttpActionResult UpdateIndividual(int id, IndividualDto individualDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var individualInDb = _context.Individuals.SingleOrDefault(i => i.Id == id);

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

            individualInDb.Name        = individualDto.Name;
            individualInDb.SematId     = individualDto.SematId;
            individualInDb.Gender      = individualDto.Gender;
            individualInDb.TelDirect   = individualDto.TelDirect;
            individualInDb.TelDakheli  = individualDto.TelDakheli;
            individualInDb.Mobile      = individualDto.Mobile;
            individualInDb.Email       = individualDto.Email;
            individualInDb.Description = individualDto.Description;
            individualInDb.WorkPlaceId = individualDto.WorkPlaceId;
            individualInDb.Updated     = DateTime.Now;
            //individualInDb.WorkPlaceId = (individualDto.WorkPlaceDto != null) ? individualDto.WorkPlaceDto.Id : (int?)null;

            _context.SaveChanges();

            return(Ok());
        }
        public IHttpActionResult CreateIndividual(IndividualDto individualDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var individual = new Individual()
            {
                Id          = individualDto.Id,
                Name        = individualDto.Name,
                SematId     = individualDto.SematId,
                Gender      = individualDto.Gender,
                TelDirect   = individualDto.TelDirect,
                TelDakheli  = individualDto.TelDakheli,
                Mobile      = individualDto.Mobile,
                Email       = individualDto.Email,
                Description = individualDto.Description,
                WorkPlaceId = individualDto.WorkPlaceId,
                Created     = DateTime.Now
            };

            _context.Individuals.Add(individual);
            _context.SaveChanges();

            individualDto.Id = individual.Id;
            return(Created(new Uri(Request.RequestUri + "/" + individual.Id), individualDto));
        }
Example #3
0
        public async Task <IndividualDto> SaveIndividualAsync(IndividualDto individualDto)
        {
            var individual           = _mapper.Map <Individual>(individualDto);
            var individualRepository = _repositoryFactory.CreateRepository <Individual>();

            var returnedIndividual = await individualRepository.SaveAsync(individual);

            var result = _mapper.Map <IndividualDto>(returnedIndividual);

            return(result);
        }
Example #4
0
        public IActionResult GetTestIndividual()
        {
            var result = new IndividualDto
            {
                FirstName = "Matthias",
                Gender    = IndividualGenderDto.Male,
                Id        = "Tra124",
                LastName  = "Müller"
            };

            return(Ok(result));
        }
Example #5
0
        public Task <long> AddPerson(IndividualDto indi)
        {
            if (indi is null)
            {
                throw new ArgumentNullException(nameof(indi));
            }

            return(AddPersonImpl(indi));

            async Task <long> AddPersonImpl(IndividualDto ind)
            {
                await this.individualRepository.AddOrUpdate(ind).ConfigureAwait(false);

                return(indi.Id);
            }
        }
Example #6
0
        public async Task <ActionResult <IndividualDto> > CreateIndividualAsync(IndividualDto dto)
        {
            var entity = _mapper.Map <Individual>(dto);

            using var uow = _uowFactory.Create();
            var individualRepo = uow.GetRepository <IIndividualRepository>();
            await individualRepo.UpsertAsync(entity);

            await uow.SaveAsync();

            var returnedEntity = await individualRepo.LoadByIdAsync(entity.Id);

            var resultDto = _mapper.Map <IndividualDto>(returnedEntity);

            return(Ok(resultDto));
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IndividualVm"/> class.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <exception cref="ArgumentNullException">dto</exception>
        public IndividualVm(IndividualDto dto)
        {
            if (dto is null)
            {
                throw new ArgumentNullException(nameof(dto));
            }

            this.Id         = dto.Id;
            this.Firstnames = dto.Firstnames;
            this.Lastname   = dto.Lastname;
            this.Sex        = dto.Sex;
            this.BirthDate  = dto.BirthDate;
            this.BirthPlace = dto.BirthPlace;
            this.DeathDate  = dto.DeathDate;
            this.DeathPlace = dto.DeathPlace;
        }
        public async Task <IndividualDto> CreateIndividualAsync(IndividualDto dto)
        {
            var gender = dto.Gender == GenderDto.Female ? Gender.Female : Gender.Male;

            var individual = _individualFactory.CreateIndividual(
                dto.FirstName,
                dto.LastName,
                gender,
                dto.BirthDate);

            var returnedIndividual = await _individualRepository.SaveAsync(individual);

            var result = _mapper.Map <IndividualDto>(returnedIndividual);

            return(result);
        }
Example #9
0
        public Task Update(IndividualDto individual)
        {
            if (individual is null)
            {
                throw new ArgumentNullException(nameof(individual));
            }

            if (individual.Id <= 0)
            {
                throw new ArgumentException("ID must be greater than zero.");
            }

            return(UpdateImpl(individual));

            async Task UpdateImpl(IndividualDto indi)
            {
                await this.individualRepository.AddOrUpdate(indi).ConfigureAwait(false);
            }
        }
        public IHttpActionResult GetIndividual(int id)
        {
            var individual = _context.Individuals
                             .Include(i => i.Semat)
                             .Include(i => i.WorkPlace.WorkPlaceType)
                             .SingleOrDefault(i => i.Id == id);

            if (individual == null || individual.Deleted == true)
            {
                return(NotFound());
            }

            var individualDto = new IndividualDto()
            {
                Id          = individual.Id,
                Name        = individual.Name,
                Gender      = individual.Gender,
                TelDirect   = individual.TelDirect,
                TelDakheli  = individual.TelDakheli,
                Mobile      = individual.Mobile,
                Email       = individual.Email,
                Description = individual.Description,
                SematDto    = new SematDto()
                {
                    Id   = individual.SematId ?? 0,
                    Name = (individual.SematId != null) ? individual.Semat.Name : String.Empty
                },
                WorkPlaceDto = new WorkPlaceDto
                {
                    Id               = individual.WorkPlaceId ?? 0,
                    Name             = (individual.WorkPlaceId != null) ? individual.WorkPlace.Name : String.Empty,
                    WorkPlaceTypeDto = new WorkPlaceTypeDto
                    {
                        Id   = (individual.WorkPlaceId != null) ? individual.WorkPlace.WorkPlaceTypeId : 0,
                        Name = (individual.WorkPlaceId != null) ? individual.WorkPlace.WorkPlaceType.Name : String.Empty
                    }
                }
            };

            return(Ok(individualDto));
        }
        private static Individual Map(IndividualDto dto)
        {
            if (dto is null)
            {
                return(null);
            }

            return(new Individual
            {
                Id = dto.Id,
                Firstnames = dto.Firstnames,
                Lastname = dto.Lastname,
                BirthDateInt = dto.BirthDate?.ToInt32(),
                BirthPlace = dto.BirthPlace,
                DeathDateInt = dto.DeathDate?.ToInt32(),
                DeathPlace = dto.DeathPlace,
                Sex = dto.Sex == FamilyTreeNet.Core.Support.Sex.Female ? 'F'
                    : dto.Sex == FamilyTreeNet.Core.Support.Sex.Male ? 'M'
                    : '?',
            });
        }
        /// <summary>Adds or updates the individual.</summary>
        /// <param name="individual">The individual.</param>
        /// <returns></returns>
        public async Task AddOrUpdate(IndividualDto individual)
        {
            if (individual == null)
            {
                throw new ArgumentNullException(nameof(individual));
            }

            var mdl = Map(individual);

            using (var conn = new MySqlConnection(this.connStr))
            {
                conn.Open();
                string sql;
                // ID is not autonumber, so read db to check whether it already exists
                sql = "SELECT count(1) FROM individual WHERE id = @Id";
                int count = await conn.ExecuteScalarAsync <int>(sql, new { mdl.Id }).ConfigureAwait(false);

                if (count == 0)
                {
                    sql = @"INSERT INTO individual (id, firstnames, lastname, sex, birth_date, birth_place, death_date, death_place, is_deleted)
                            VALUES (@Id, @Firstnames, @Lastname, @Sex, @BirthDateInt, @BirthPlace, @DeathDateInt, @DeathPlace, 0)";
                }
                else
                {
                    sql = @"UPDATE individual SET
                                firstnames = @Firstnames,
                                lastname = @Lastname,
                                sex = @Sex,
                                birth_date = @BirthDateInt,
                                birth_place = @BirthPlace,
                                death_date = @DeathDateInt,
                                death_place = @DeathPlace,
                                is_deleted = 0
                            WHERE id = @Id";
                }

                await conn.ExecuteAsync(sql, mdl).ConfigureAwait(false);
            }
        }
Example #13
0
        public async Task AddOrUpdate(IndividualDto individual)
        {
            if (individual is null)
            {
                throw new System.ArgumentNullException(nameof(individual));
            }

            var indi = individual.Id == 0 ? null : await this.context.Individuals.FirstOrDefaultAsync(i => i.Id == individual.Id).ConfigureAwait(false);

            if (indi == null)
            {
                if (individual.Id == 0)
                {
                    individual.Id = (await this.context.Individuals.Select(i => i.Id).MaxAsync().ConfigureAwait(false)) + 1;
                }

                indi = new Individual {
                    Id = individual.Id
                };
                this.context.Individuals.Add(indi);
            }

            indi.IsDeleted  = false;
            indi.Firstnames = individual.Firstnames;
            indi.Lastname   = individual.Lastname;
            // C#8: switch expression
            indi.Sex = individual.Sex == FamilyTreeNet.Core.Support.Sex.Male ? 'M'
                    : individual.Sex == FamilyTreeNet.Core.Support.Sex.Female ? 'F'
                    : '?';

            indi.BirthDateInt = individual.BirthDate?.ToInt32();
            indi.BirthPlace   = individual.BirthPlace;
            indi.DeathDateInt = individual.DeathDate?.ToInt32();
            indi.DeathPlace   = individual.DeathPlace;

            await this.context.SaveChangesAsync().ConfigureAwait(false);
        }
Example #14
0
        /// <summary>
        /// GetFakeCustomerAccountDto - returns fake CustomerAccountDto object
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="subscriberID"></param>
        /// <param name="fakeBillingAccountIdDto"></param>
        /// <param name="fakeCustomerAccountIdDto"></param>
        /// <returns></returns>
        public CustomerAccountDto GetFakeCustomerAccountDto(string firstName, string lastName, string subscriberID, BillingAccountIdDto fakeBillingAccountIdDto, CustomerAccountIdDto fakeCustomerAccountIdDto)
        {
            var fakeIndividualName = new IndividualNameDto()
            {
                GivenNames = firstName,
                FamilyNames = lastName
            };

            var fakeIndividualDto = new IndividualDto()
            {
                IndividualName = fakeIndividualName
            };

            var fakeCustomerDto = new CustomerDto()
            {
                Individual = fakeIndividualDto
            };

            var fakeCustomerAccountDto = new CustomerAccountDto()
            {
                AccountID = subscriberID,
                BillingAccountId = fakeBillingAccountIdDto,
                CustomerAccountId = fakeCustomerAccountIdDto,
                Customer = fakeCustomerDto
            };

            return fakeCustomerAccountDto;
        }
Example #15
0
        public async Task <IActionResult> PutIndividualAsync([FromBody] IndividualDto individualDto)
        {
            var result = await _individualUpdateService.SaveIndividualAsync(individualDto);

            return(Ok(result));
        }
        public async Task <IActionResult> CreateIndividualAsync([FromBody] IndividualDto dto)
        {
            var result = await _individualService.CreateIndividualAsync(dto);

            return(Ok(result));
        }