예제 #1
0
        public async Task CreateAndDeleteAJourney()
        {
            var journey = new Journey
            {
                JourneyName      = "AddDeleteTest",
                GeometryFileName = "/route.geojson",
                Bio       = $"This is a test Journey created on {DateTime.Now}",
                Active    = true,
                Created   = DateTime.Now,
                ImagePath = "/images/DSC06102small.jpg"
            };

            var result = await journey.PostAsync(_azureSql);

            Assert.True(result);

            var getFromDb = await Journey.GetByJourneyNameAsync(journey.JourneyName, _azureSql);

            Assert.True(getFromDb.Any());

            var created     = getFromDb.FirstOrDefault();
            var checkDelete = await created.DeleteAsync(_azureSql);

            Assert.True(checkDelete);
        }
        public async Task <IActionResult> AddJourneyAsync([Bind("JourneyName,Bio,GeometryFileName,ImagePath")] Journey newJourney)
        {
            if (newJourney != null && !string.IsNullOrWhiteSpace(newJourney.JourneyName) && newJourney.JourneyName.Length <= 100 &&
                !string.IsNullOrWhiteSpace(newJourney.Bio) && newJourney.Bio.Length <= 300 &&
                !string.IsNullOrWhiteSpace(newJourney.GeometryFileName) && newJourney.GeometryFileName.Length <= 300 &&
                !string.IsNullOrWhiteSpace(newJourney.ImagePath) && newJourney.ImagePath.Length <= 100)
            {
                newJourney.Active = true;

                var checkCreateJourney = await newJourney.PostAsync(_azureSQL);

                // Create a default team to go with this journey, because every journey need a team to enable anonymous submissions.
                var defaultTeam = new Team
                {
                    TeamName    = $"{newJourney.JourneyName} Team",
                    TeamWebsite = "https://thomasryan.xyz/",
                    Bio         = $"Every Journey has a Team. This is the default team for {newJourney.JourneyName}.",
                    Active      = true,
                    Created     = DateTime.Now
                };

                var checkCreateDefaultTeam = await defaultTeam.PostAsync(_azureSQL);

                var defaultNickname = new Nickname
                {
                    Name    = $"{newJourney.JourneyName} Team",
                    Bio     = $"This is nickname for those that prefer to remain anonymous.",
                    Active  = true,
                    Created = DateTime.Now
                };

                var checkCreateDefaultNickname = await defaultNickname.PostAsync(_azureSQL);

                if (checkCreateJourney && checkCreateDefaultTeam && checkCreateDefaultNickname)
                {
                    return(Redirect($"/{newJourney.JourneyName}"));
                }
                else
                {
                    return(View("Add"));
                }
            }
            else
            {
                return(View("Add"));
            }
        }