コード例 #1
0
 public async Task <ActionResult <ParticipantsDTO> > DeleteParticipantFromEvent(int EventId, int UserId)
 {
     try
     {
         ParticipantsDTO participantsDto = new ParticipantsDTO();
         var             participant     = _mapper.Map <Participants>(participantsDto);
         participant.EventId = EventId;
         participant.UserId  = UserId;
         _participantsRepository.Delete(participant);
         if (await _participantsRepository.SaveChangeAsync())
         {
             return(Ok());
         }
     }
     catch (Exception)
     {
         return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
     }
     return(BadRequest());
 }
コード例 #2
0
        public async Task <ActionResult <ParticipantsDTO> > AddParticipant(int EventId, int UserId, ParticipantsDTO participantsDto)
        {
            try
            {
                var participant = _mapper.Map <Participants>(participantsDto);
                participant.EventId = EventId;
                participant.UserId  = UserId;

                _participantsRepository.CreateParticipants(participant);

                var eventTemp = await _eventRepository.GetEventByIdAsync(EventId);

                var    mappedEvent = _mapper.Map <EventFullDTO>(eventTemp);
                string eventTitle  = mappedEvent.EventName;

                var hostUser = await _userRepository.GetUserByIdAsync(eventTemp.UserId);

                var    mappedHost = _mapper.Map <UserFullDTO>(hostUser);
                string hostName   = mappedHost.Name;
                string hostEmail  = mappedHost.Email;

                var participantUser = await _userRepository.GetUserByIdAsync(UserId);

                var    mappedParticipant = _mapper.Map <UserFullDTO>(participantUser);
                string participantsName  = mappedParticipant.Name;

                MailModel mailModel = new MailModel();
                mailModel.From    = "*****@*****.**";
                mailModel.To      = participantUser.Email;
                mailModel.Subject = "You have joined the event " + eventTitle;
                mailModel.Body    = "Hi " + participantsName + "\n ! You have joined the event hosted by \n " + hostName + ". Here is the " + hostName + "'s contact email address: " + hostEmail + " We hope you will have fun. Thanks for using our app!";
                _emailService.SendEmail(mailModel);

                if (await _participantsRepository.SaveChangeAsync())
                {
                    return(Ok());
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest());
        }