public string AcceptInvitation(int EventId, string Email) { var repoEvent = _contextManager.CreateRepositiry <IEventRepo>(); var companyEvent = repoEvent.GetById(EventId); _subscriptionService.CheckSubscription(companyEvent.CompanyId); if (companyEvent == null) { throw new ValidationException("Event not found."); } var repoUser = _contextManager.CreateRepositiry <IUserRepo>(); var user = repoUser.GetUserByEmail(Email); if (user == null) { throw new ValidationException("User not found."); } var repoEventUser = _contextManager.CreateRepositiry <IEventUserLinkRepo>(); var eventUser = repoEventUser.GetRecordByEventAndUser(user.Id, EventId); if (!(eventUser == null)) { throw new ValidationException("User is already added to the event."); } var entity = new EventUserLink { EventId = EventId, UserId = user.Id, UserEventRole = (int)Model.Enums.EventUserRoleEnum.User }; repoEventUser.Add(entity); _contextManager.Save(); SendEventTicket(companyEvent, user); return("You successfully join the Event, the ticket send to your email"); }
public EventDto CreateEvent(EventCreateDto dto) { _subscriptionService.CheckSubscription(dto.CompanyId); try { var repoUser = _contextManager.CreateRepositiry <IUserRepo>(); var user = repoUser.GetById(dto.UserId); if (user == null) { throw new ValidationException("User not found"); } var entity = _mapper.Map <Event>(dto); var repo = _contextManager.CreateRepositiry <IEventRepo>(); repo.Add(entity); _contextManager.Save(); //add user to the event var repoEventUser = _contextManager.CreateRepositiry <IEventUserLinkRepo>(); var eventUser = new EventUserLink { EventId = entity.Id, UserId = user.Id, UserEventRole = (int)Model.Enums.EventUserRoleEnum.Owner }; repoEventUser.Add(eventUser); _contextManager.Save(); return(_mapper.Map <EventDto>(entity)); } catch { throw new ValidationException("Sorry, unexpected error."); } }