Example #1
0
        public static async Task <string> CreateAndStore(string longUrl)
        {
            //DynaDB.Client = new AmazonDynamoDBClient(new StoredProfileAWSCredentials("default"), RegionEndpoint.EUWest1);
            //DynaDB.urlsTable = Table.LoadTable(DynaDB.Client, "MnfyUrls");
            string newKey = Guid.NewGuid().ToString("N").Substring(0, 6).ToLower();

            var alreadyExists = true;

            while (alreadyExists)
            {
                alreadyExists = await DynaDB.ReadingItem(newKey, false);

                if (!alreadyExists)
                {
                    Document newItemDocument = new Document();
                    newItemDocument["UrlKey"]        = newKey;
                    newItemDocument["LongURL"]       = longUrl;
                    newItemDocument["TwitterHandle"] = "@PaulLogan";
                    newItemDocument["DeletionDate"]  = "2021/30/25";
                    DynaDB.WritingNewItem(newItemDocument).Wait();
                }
                else
                {
                    newKey = Guid.NewGuid().ToString("N").Substring(0, 6).ToLower();
                }
            }
            return(newKey);
        }
Example #2
0
        public async Task <string> GetURL(string shortURL)
        {
            var longURL = "";

            if (shortURL != null)
            {
                var found = await DynaDB.ReadingItem(shortURL, false);

                if (found)
                {
                    var toJSON = DynaDB.mnfyUrlRecord.ToJson();
                    var obj    = JsonSerializer.Deserialize <MnfyUrl>(toJSON);
                    longURL = obj.LongURL;
                }
            }
            return(longURL);
        }