public ApiResponse <ParticipantApiModel> CreateParticipant(ParticipantApiModel participantApiModel)
        {
            var response        = new ApiResponse <ParticipantApiModel>();
            var participantData = _context.Participants
                                  .Where(x => x.Email.ToLower() == participantApiModel.Email.ToLower() && x.IsActive).FirstOrDefault();

            if (participantData != null)
            {
                response.IsSucceeded = true;
                response.Result      = participantData.ToParticipantApiModel();
            }
            else
            {
                var participant = new Participant
                {
                    Name        = participantApiModel.Name,
                    DateOfBirth = participantApiModel.DateOfBirth,
                    Email       = participantApiModel.Email,
                    IsActive    = true
                };
                _context.Participants.Add(participant);
                int rowAffective = _context.SaveChanges();

                response.IsSucceeded = rowAffective > 0;
                response.Result      = response.IsSucceeded ? participant.ToParticipantApiModel() : null;
            }
            return(response);
        }
Example #2
0
        public IHttpActionResult CreateParticipant([FromBody] ParticipantApiModel participant)
        {
            var apiResponse = _participantQueryService.CreateParticipant(participant);

            return(Ok(apiResponse));
        }