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 CompanyDto UpdateCompany(int id, CompanyDto dto) { _subscriptionService.CheckSubscription(id); var repo = _contextManager.CreateRepositiry <ICompanyRepo>(); var company = repo.GetCompanyByName(dto.Name); if (!(company == null)) { if ((company.Name == dto.Name) && !(company.Id == dto.Id)) { throw new ValidationException("Company with name <" + dto.Name + "> is already exists."); } } var data = repo.GetById(id); if (data == null) { throw new ValidationException("Company not found."); } data.Name = dto.Name; data.Type = dto.Type; data.Description = dto.Description; _contextManager.Save(); return(_mapper.Map <CompanyDto>(data)); }