Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="participantModel"></param>
        /// <returns></returns>
        public async Task <ParticipantModel> CreateOrUpdate(ParticipantModel participantModel)
        {
            if (participantModel.Id == Guid.Empty)
            {
                participantModel.Id     = Guid.NewGuid();
                participantModel.HashId = Helpers.Hash256Tool.Sha256HashString(participantModel.Id.ToString());
            }
            var participantDb = await _participantRepository.FindBy(s => s.Id == participantModel.Id).ConfigureAwait(false);

            if (participantDb == null)
            {
                var participant = AutoMapper.Mapper.Map <Participant>(participantModel);
                _participantRepository.Create(participant);
                _participantRepository.Save(true, false, participantModel.Id);
            }
            else
            {
                AutoMapper.Mapper.Map(participantModel, participantDb);
                _participantRepository.Update(participantDb);
                _participantRepository.Save(true, false, participantModel.Id);
            }

            return(participantModel);
        }