Beispiel #1
0
        private AttendeeService CreateAttendeeService()
        {
            var userId          = Guid.Parse(User.Identity.GetUserId());
            var attendeeService = new AttendeeService(userId);

            return(attendeeService);
        }
Beispiel #2
0
        public IHttpActionResult Get()
        {
            AttendeeService attendeeService = CreateAttendeeService();
            var             attendees       = attendeeService.GetAttendees();

            return(Ok(attendees));
        }
 public void ResetAllHasWon_ShouldReturn_NonNull_Boolean()
 {
     IAttendeeService service = new AttendeeService();
     bool returnSuccess = service.ResetAllHasWon();
     //Assert
     Assert.IsInstanceOfType(returnSuccess, typeof (bool));
 }
 public void DeleteAll_ShouldReturn_NonNull_Boolean()
 {
     //Act
     IAttendeeService service = new AttendeeService();
     bool returnSuccess = service.DeleteAll();
     //Assert
     Assert.IsInstanceOfType(returnSuccess, typeof (bool));
 }
 public void InsertAll_ShouldReturn_NonNull_Boolean()
 {
     //Act
     IAttendeeService service = new AttendeeService();
     bool returnSuccess = service.InsertAll(new List<AttendeeDTO>());
     //Assert
     Assert.IsInstanceOfType(returnSuccess, typeof(bool));
 }
 public void GetAll_ShouldReturn_NonNull_ListOf_AttendeeDTO()
 {
     //Act
     IAttendeeService service = new AttendeeService();
     IList<AttendeeDTO> attendeeDtos = service.GetAll();
     //Assert
     attendeeDtos.ShouldNotBeNull("Expected AttendeeDTO List Not To Be Null");
     Assert.IsInstanceOfType(attendeeDtos, typeof (IList<AttendeeDTO>));
 }
Beispiel #7
0
        public BookingController(IHttpContextAccessor httpContextAccessor, ISecurityService securityService)
        {
            Session = httpContextAccessor.HttpContext.Session;

            _meetingService  = new MeetingService();
            _attendeeService = new AttendeeService();
            service          = securityService;

            email = Session.GetString("account");
        }
 public void SetHasWon_ShouldReturn_NonNull_Boolean()
 {
     using (new TransactionScope()) {
         //Act
         IAttendeeService service = new AttendeeService();
         bool returnSuccess = service.SetHasWon(1);
         //Assert
         Assert.IsInstanceOfType(returnSuccess, typeof (bool));
     }
 }
        public AttendeeService Build()
        {
            if (_repo == null)
            {
                //-- create a mock
                var repoMock = new Mock<IRepositoryAsync<Attendee>>();
                _repo = repoMock.Object;

            }

            var service = new AttendeeService(_repo);
            return service;
        }
 public void Insertll_ShouldReturn_NonNull_Boolean()
 {
     //Arrange
     const bool success = true;
     _mockAttendee.Expect(x => x.InsertAll(new List<AttendeeDTO>())).IgnoreArguments().Return(success).Repeat.Once();
     _mockRepository.ReplayAll();
     //Act
     IAttendeeService service = new AttendeeService(_mockAttendee);
     bool returnSuccess = service.InsertAll(new List<AttendeeDTO>());
     //Assert
     _mockRepository.VerifyAll();
     Assert.IsInstanceOfType(returnSuccess, typeof(bool));
 }
 public void GetAll_ShouldReturn_NonNull_ListOf_AttendeeDTO()
 {
     //Arrange
     _mockAttendee.Expect(x => x.GetAll()).Return(new List<AttendeeDTO> ()).Repeat.Once();
     _mockRepository.ReplayAll();
     //Act
     IAttendeeService service = new AttendeeService(_mockAttendee);
     IList<AttendeeDTO> attendeeDtos = service.GetAll();
     //Assert
     _mockRepository.VerifyAll();
     attendeeDtos.ShouldNotBeNull("Expected AttendeeDTO List Not To Be Null");
     Assert.IsInstanceOfType(attendeeDtos, typeof(IList<AttendeeDTO>));
 }
 public void DeleteAll_ShouldReturn_NonNull_Boolean()
 {
     //Arrange
     const bool success = true;
     _mockAttendee.Expect(x => x.DeleteAll()).Return(success).Repeat.Once();
     _mockRepository.ReplayAll();
     //Act
     IAttendeeService service = new AttendeeService(_mockAttendee);
     bool returnSuccess = service.DeleteAll();
     //Assert
     _mockRepository.VerifyAll();
     Assert.IsInstanceOfType(returnSuccess, typeof(bool));
 }
 public void InsertAll_ShouldReturn_NonNull_Boolean()
 {
     //Arrange
     IList<AttendeeDTO> attendeeDtos = new List<AttendeeDTO> { new AttendeeDTO { FirstName = "FName", LastName = "LName", Company = "Company", Email = "*****@*****.**", IsEligible = true, HasWon = true } };
     using (new TransactionScope())
     {
         //Act
         IAttendeeService service = new AttendeeService();
         bool returnSuccess = service.InsertAll(attendeeDtos);
         //Assert
         Assert.IsInstanceOfType(returnSuccess, typeof(bool));
     }
 }
        public static async Task RunAsync([ServiceBusTrigger("userregistration", Connection = "ServiceBusConnectionString")] string myQueueItem, string messageId, ILogger log)
        {
            log.LogInformation($"C# ServiceBus queue trigger function processed message: {messageId}");

            //Load the encryption module
            var encryptionService = new EncryptionService();
            //Get the Object from the ServiceBus
            var registrationRequest = encryptionService.DecryptRegistrationRequest(JsonConvert.DeserializeObject <UserRegistrationRequest>(myQueueItem));
            //Get attendee service for table storage communication
            var attendeeService = new AttendeeService();
            //GetEmailService
            var emailService = new EmailService();
            //GetGraphApiService
            var graphApiService = new GraphApiService();

            //Save Attendee information to the table storage --> may be crypted
            var attendee = encryptionService.DecryptÁttendeeRecord(attendeeService.CreateAttendeeRecord(registrationRequest));

            //Register Attendee in AzureAD

            //Build AdUser Object
            string tenantDomainName = System.Environment.GetEnvironmentVariable("tenantDomainName");
            var    AdUser           = new User
            {
                AccountEnabled = true,
                //Generated user name with @<tenant>.onmicrosoft.com at the end
                UserPrincipalName = attendee.Username + tenantDomainName,
                DisplayName       = attendee.Name + "  " + attendee.Surname,
                Surname           = attendee.Surname,
                GivenName         = attendee.Name,
                UserType          = "Guest",
                UsageLocation     = "DE",
                CompanyName       = "JHV-Mitglieder",
                MailNickname      = attendee.Name + "" + attendee.Surname,
                PasswordProfile   = new PasswordProfile
                {
                    ForceChangePasswordNextSignIn = false,
                    Password = attendee.Password
                },
            };

            //ToDo: Create error handling!
            //CreateAdUser
            var createdUser = await graphApiService.graphClient.Users
                              .Request()
                              .AddAsync(AdUser);

            //Inform Attendee via Mail
            await emailService.SendRegistrationSucceededMail(attendee.Email, attendee.Name + " " + attendee.Surname, attendee.Username, attendee.Password);
        }
 public void Insert_ShouldReturn_NonNull_Boolean()
 {
     using (new TransactionScope()) {
         //Arrange
         long attendeeID = new AttendeeService().GetAll()[0].AttendeeID;
         long sponsorID = new SponsorService().GetAllThatProvidedSwag()[0].SponsorID;
         long swagID = new SwagService().GetAllBySponsor(sponsorID)[0].SwagID;
         //Act
         IWinnerService service = new WinnerService();
         bool result = service.Insert(new WinnerDTO {AttendeeID = attendeeID, SponsorID = sponsorID, SwagID = swagID, Name = "Big Winner",});
         //Assert
         Assert.IsInstanceOfType(result, typeof (bool));
     }
 }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            //Get MetadataInformation
            var metaInformationService = new MetaInformationService();
            //Get AttendeeService
            var attendeeService = new AttendeeService();

            //Check if Deadline is already reached
            if (metaInformationService.IsRegistrationDeadlineReached())
            {
                return(new BadRequestObjectResult("Registrierung nicht mehr moeglich. Anmeldeschluss erreicht!"));
            }

            //Check if Registration is already allowed
            if (!metaInformationService.IsRegistrationStartReached())
            {
                return(new BadRequestObjectResult("Registrierung noch nicht moeglich. Bitte gedulden Sie sich noch ein bisschen!"));
            }


            //Validate User Input
            //Get Dictionary out of input
            Dictionary <string, string> InputMessage = JsonConvert.DeserializeObject <Dictionary <string, string> >(new StreamReader(req.Body).ReadToEnd());

            if (!InputMessage.ContainsKey("name") ||
                !InputMessage.ContainsKey("surname") ||
                !InputMessage.ContainsKey("email") ||
                !InputMessage.ContainsKey("birthday") ||
                !InputMessage.ContainsKey("city") ||
                !InputMessage.ContainsKey("zip"))
            {
                return(new BadRequestObjectResult("Not all needed parameters are set!"));
            }

            //Check if Birthday is valid input
            if (!DateTime.TryParseExact(InputMessage["birthday"], "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime UserBirthday))
            {
                log.LogError("Failed to parse Birthday! Input: " + InputMessage["birthday"].ToString());
                return(new BadRequestObjectResult("Could not parse Birthday!"));
            }


            //All needed parameters are present, lets create an object for that to work with
            var registrationRequest = new UserRegistrationRequest()
            {
                Name         = InputMessage["name"],
                Surname      = InputMessage["surname"],
                EmailAddress = InputMessage["email"],
                Birthday     = UserBirthday.ToString(),
                City         = InputMessage["city"],
                ZipCode      = InputMessage["zip"]
            };

            //ToDo: Validate if user is Eligable for attendance based on Validation Module
            Dictionary <string, string> validationParameters = new Dictionary <string, string>()
            {
                { "vorname", registrationRequest.Name },
                { "nachname", registrationRequest.Surname },
                { "ort", registrationRequest.City },
                { "plz", registrationRequest.ZipCode },
                { "geburtsdat", $"{UserBirthday.Day.ToString("00")}/{UserBirthday.Month.ToString("00")}/{UserBirthday.Year.ToString()}" }
            };

            if (!attendeeService.IsValidMember(validationParameters, "AND"))
            {
                return(new BadRequestObjectResult("Zu diesem Benutzer konnte keine Mitgliedschaft gefunden werden! Bitte ueberpruefe deine Eingaben auf Fehler."));
            }
            //If yes, extract userId from CSV and write it to the request
            string memberId = attendeeService.GetMemberIdFromMemberTable(validationParameters, "AND");

            //Check if account exists already via userId
            if (attendeeService.DoesUserExist(memberId))
            {
                return(new BadRequestObjectResult("Fuer diese Mitgliedschaft liegt bereits eine Registrierung vor!"));
            }

            //Check if account exists already via E-Mail
            if (attendeeService.IsEmailAlreadyUsed(registrationRequest.EmailAddress))
            {
                return(new BadRequestObjectResult("Diese E-Mail Adresse wurde bereits verwendet!"));
            }



            //Feedback
            return(new OkObjectResult("OK!"));
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            //Get encryption service
            var encryptionService = new EncryptionService();
            //Get MetadataInformation
            var metaInformationService = new MetaInformationService();
            //Get attendee service
            var attendeeService = new AttendeeService();


            //Check if Deadline is already reached
            if (metaInformationService.IsRegistrationDeadlineReached())
            {
                return(new BadRequestObjectResult("Registration not possible. Event Deadline Reached!"));
            }

            //Check if Registration is already allowed
            if (!metaInformationService.IsRegistrationStartReached())
            {
                return(new BadRequestObjectResult("Registration not yet possible. Plese stay tuned!"));
            }

            //Validate User Input
            //Get Dictionary out of input
            Dictionary <string, string> InputMessage = JsonConvert.DeserializeObject <Dictionary <string, string> >(new StreamReader(req.Body).ReadToEnd());

            if (!InputMessage.ContainsKey("name") ||
                !InputMessage.ContainsKey("surname") ||
                !InputMessage.ContainsKey("email") ||
                !InputMessage.ContainsKey("birthday") ||
                !InputMessage.ContainsKey("city") ||
                !InputMessage.ContainsKey("zip"))
            {
                return(new BadRequestObjectResult("Not all needed parameters are set!"));
            }

            //Check if Birthday is valid input
            if (!DateTime.TryParseExact(InputMessage["birthday"], "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime UserBirthday))
            {
                return(new BadRequestObjectResult("Could not parse Birthday!"));
            }


            //All needed parameters are present, lets create an object for that to work with
            var registrationRequest = new UserRegistrationRequest()
            {
                Name         = InputMessage["name"],
                Surname      = InputMessage["surname"],
                EmailAddress = InputMessage["email"],
                Birthday     = UserBirthday.ToString(),
                City         = InputMessage["city"],
                ZipCode      = InputMessage["zip"]
            };

            //Validate if user is Eligable for attendance based on Validation Module
            Dictionary <string, string> validationParameters = new Dictionary <string, string>()
            {
                { "vorname", registrationRequest.Name },
                { "nachname", registrationRequest.Surname },
                { "ort", registrationRequest.City },
                { "plz", registrationRequest.ZipCode },
                { "geburtsdat", $"{UserBirthday.Day.ToString("00")}/{UserBirthday.Month.ToString("00")}/{UserBirthday.Year.ToString()}" }
            };

            if (!attendeeService.IsValidMember(validationParameters, "AND"))
            {
                return(new BadRequestObjectResult("User not found in member database!"));
            }
            //If yes, extract userId from CSV and write it to the request
            string memberId = attendeeService.GetMemberIdFromMemberTable(validationParameters, "AND");

            registrationRequest.UserId = memberId;


            //Check if account exists already via userId
            if (attendeeService.DoesUserExist(memberId))
            {
                return(new BadRequestObjectResult("You are already registered with that membership!"));
            }

            //Check if account exists already via E-Mail
            if (attendeeService.IsEmailAlreadyUsed(registrationRequest.EmailAddress))
            {
                return(new BadRequestObjectResult("That E-Mail is already used!"));
            }

            //Encrypt user information for further processing
            registrationRequest = encryptionService.EncryptRegistrationRequest(registrationRequest);

            //Create Queue Item for further processing
            var queueClient = new QueueClient(System.Environment.GetEnvironmentVariable("ServiceBusConnectionString"), "userregistration");

            //Send Message
            string message        = JsonConvert.SerializeObject(registrationRequest);
            var    encodedMessage = new Message()
            {
                Body        = Encoding.UTF8.GetBytes(message),
                ContentType = "application/json",
            };
            await queueClient.SendAsync(encodedMessage);

            //Feedback
            return(new OkObjectResult("OK!"));
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            //Get encryption service
            var encryptionService = new EncryptionService();
            //Get attendee service
            var attendeeService = new AttendeeService();

            //Build request mode
            string userId;
            string exportFormat;

            var InputMessage = req.Query;

            //set userId to parse
            if (InputMessage.ContainsKey("userId"))
            {
                userId = InputMessage["userId"];
            }
            else
            {
                userId = "";
            }

            //Set export format
            if (InputMessage.ContainsKey("exportFormat"))
            {
                exportFormat = InputMessage["exportFormat"];
            }
            else
            {
                exportFormat = "json";
            }
            if (exportFormat != "json" && exportFormat != "csv")
            {
                return(new BadRequestObjectResult("That export format is not supported!"));
            }

            //Create List to be filled based on userId
            var attendeeList = new List <AttendeeRecord>();

            if (userId == "")
            {
                //Get all attendee records
                var encryptedattendees = attendeeService.GetAllAttendeeRecords();
                foreach (var attendee in encryptedattendees)
                {
                    attendeeList.Add(encryptionService.DecryptÁttendeeRecord(attendee));
                }
            }
            else
            {
                //Get specific record
                var attendeeRecord = attendeeService.GetAttendeeRecord(userId);
                if (attendeeRecord == null)
                {
                    return(new NotFoundObjectResult("That user could not be found!"));
                }

                attendeeList.Add(encryptionService.DecryptÁttendeeRecord(attendeeService.GetAttendeeRecord(userId)));
            }

            //Format list based on export format and return
            switch (exportFormat)
            {
            case "json":
                //Handle Json response
                return(new OkObjectResult(JsonConvert.SerializeObject(attendeeList)));

            case "csv":
                //Handle CSV Response
                var stringBuilder = new StringBuilder();
                var TextWriter    = new StringWriter(stringBuilder);
                var csv           = new CsvWriter(TextWriter, System.Globalization.CultureInfo.InvariantCulture);
                csv.WriteRecords(attendeeList);
                return(new OkObjectResult(stringBuilder.ToString()));

            default:
                return(new BadRequestObjectResult("That output format is not supported!"));
            }
        }
Beispiel #19
0
 public AttendeesController(IHttpContextAccessor httpContextAccessor)
 {
     _attendeeService = new AttendeeService();
     Session          = httpContextAccessor.HttpContext.Session;
     Email            = Session.GetString("account");
 }