Пример #1
0
        public void TestEventCharacter()
        {
            int      eventID        = 10;
            string   characterName  = "Something";
            string   characterRole  = "Healer";
            DateTime signUpDateTime = new DateTime(2020, 11, 1, 10, 30, 0);

            EventCharacter eventCharacter = new EventCharacter(eventID, characterName, characterRole, signUpDateTime);
            int            year           = eventCharacter.SignUpDateTime.Year;
            int            month          = eventCharacter.SignUpDateTime.Month;
            int            day            = eventCharacter.SignUpDateTime.Day;
            int            hour           = eventCharacter.SignUpDateTime.Hour;
            int            minute         = eventCharacter.SignUpDateTime.Minute;
            int            second         = eventCharacter.SignUpDateTime.Second;

            Assert.AreEqual(10, eventCharacter.EventID);
            Assert.AreEqual("Something", eventCharacter.CharacterName);
            Assert.AreEqual("Healer", eventCharacter.CharacterRole);
            Assert.AreEqual(2020, year);
            Assert.AreEqual(11, month);
            Assert.AreEqual(1, day);
            Assert.AreEqual(10, hour);
            Assert.AreEqual(30, minute);
            Assert.AreEqual(0, second);
        }
Пример #2
0
        public ActionResult <EventCharacter> Post([FromBody] EventCharacter ec, [FromHeader(Name = "x-rowid")] byte[] rowId)
        {
            IAuthService authService = new JWTService(clientSettings.Value.SecretKey);
            string       token       = HttpContext.Request.Headers["Authorization"];

            try
            {
                if (!authService.IsTokenValid(token))
                {
                    return(BadRequest("Unauthorized Access"));
                }
                else
                {
                    if (eventProcessor.HasEventChangedRowVersion(ec.EventID, rowId))
                    {
                        // TODO change response type
                        return(BadRequest("The information about event you tried to join has changed. Joining event was unsuccessful"));
                    }

                    if (eventCharacterProcessor.JoinEvent(ec.EventID, ec.CharacterName, ec.CharacterRole, ec.SignUpDateTime))
                    {
                        return(ec);
                    }
                    return(BadRequest("Invalid data."));
                }
            } catch
            {
                return(BadRequest("Unauthorized Access"));
            }
        }
Пример #3
0
        private void JoinEventButton_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(characterRoleBox.Text))
            {
                EventCharacter newEventCharacter = new EventCharacter()
                {
                    EventID        = int.Parse(eventIDBox.Text),
                    CharacterName  = (string)App.Current.Properties["SelectedCharacter"],
                    CharacterRole  = characterRoleBox.Text,
                    SignUpDateTime = DateTime.Now,
                };

                var response = client.PostAsJsonAsync("api/Guild/events/join", newEventCharacter).Result;

                if (response.IsSuccessStatusCode)
                {
                    WpfMessageBox.Show("Successfully joined event", "You have successfully joined this event!", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    WpfMessageBox.Show("Something went wrong", "An error has occured while joining the event\n Error code : " + response.ReasonPhrase, MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                WpfMessageBox.Show("No role specified", "Please fill in your role for this event!", MessageBoxButton.OK, MessageBoxImage.Question);
            }
            DataGrid.FillDataGrid();
            Close();
        }
Пример #4
0
        public bool InsertEventCharacter(EventCharacter eventParticipant)
        {
            if (!DBConnection.IsConnectionAvailable())
            {
                log.Error(exception: new TimeoutException(), "No connection to either the internet or the database available.");
                return(false);
            }

            // Either join participant list or the waiting list by checking if participant list reached the maximum amout of sign-ups.
            using (IDbConnection conn = DBConnection.GetConnection())
            {
                try
                {
                    if (!IsParticipantListFull(eventParticipant.EventID))
                    {
                        log.Info("Inserting character: @characterName into the participant list for event ID: @eventID", eventParticipant.CharacterName, eventParticipant.EventID);
                        int rowsAffected = conn.Execute(@"INSERT INTO EventCharacter (eventID, characterName, characterRole, signUpDateTime) " +
                                                        "VALUES (@EventID, @CharacterName, @CharacterRole, @SignUpDateTime)", eventParticipant);

                        if (rowsAffected > 0)
                        {
                            log.Info("Successfully inserted character: @characterName into the participant list for the event: @eventID", eventParticipant.CharacterName, eventParticipant.EventID);
                            return(true);
                        }
                        log.Error(new Exception(), "Unable to insert character: @characterName into the participant list for event ID: @eventID", eventParticipant.CharacterName, eventParticipant.EventID);
                        return(false);
                    }
                    else
                    {
                        log.Info("Inserting character: @characterName into the waiting list for event ID: @eventID", eventParticipant.CharacterName, eventParticipant.EventID);
                        int rowsAffected = conn.Execute(@"INSERT INTO EventCharacterWaitingList (eventID, characterName, characterRole, signUpDateTime) " +
                                                        "VALUES (@EventID, @CharacterName, @CharacterRole, @SignUpDateTime)", eventParticipant);

                        if (rowsAffected > 0)
                        {
                            log.Info("Successfully inserted character: @characterName into the waiting list for the event: @eventID", eventParticipant.CharacterName, eventParticipant.EventID);
                            return(true);
                        }
                        log.Error(new Exception(), "Unable to insert character: @characterName into the waiting list for event ID: @eventID", eventParticipant.CharacterName, eventParticipant.EventID);
                        return(false);
                    }
                } catch (SqlException ex)
                {
                    log.Trace("SQLException encountered while inserting the character into the event list.");
                    log.Error(ex, "Unable to insert character into the event list.");
                    return(false);
                }
            }
        }
Пример #5
0
        public Boolean JoinEvent(int eventID, string characterName, string role, DateTime signUpDateTime)
        {
            EventCharacter eventCharacterToBeAdded = new EventCharacter(eventID, characterName, role, signUpDateTime);

            return(eventCharacterAccess.InsertEventCharacter(eventCharacterToBeAdded));
        }