public ActionResult <GeneralAPIResponse> ServerDetailsHi() { var generalAPIResponse = new GeneralAPIResponse(); var tempString1 = "Okay, You have User Role"; generalAPIResponse.ListOfResponses.Add(tempString1); generalAPIResponse.dateTimeOfResponse = DateTime.Now; return(generalAPIResponse); }
public async Task <ActionResult <GeneralAPIResponse> > PostQuote(QuoteCubeAdd quote) { var tempQuoteHelpers = new QuoteHelpers(); var tempSecretPhrase = tempQuoteHelpers.ReturnTheSecretForAdding(); var tempItemViewModel = new GeneralAPIResponse(); var tempString1 = "Empty"; var tempString2 = "Empty"; if (quote.SecretPhrase.Equals(tempSecretPhrase) == true) { //okay secret phrase provided //add this up. //build our adding object var tempQuote = new Quote(); tempQuote.QuoteContent = quote.QuoteContent; tempQuote.QuoteTitle = quote.QuoteTitle; //now the object is ready. _context.Quotes.Add(tempQuote); await _context.SaveChangesAsync(); tempString1 = "Okay man. Quote has been added. I really hope this is the API server owner adding all these quotes"; tempString2 = "The id of the newly added Quote is " + tempQuote.QuoteId; } else { tempString1 = "Dude. You dont have the secret phrase. Only secret phrase knowing folks can add quotes to this sytem"; tempString2 = "Sincere Apologies"; } //lets add all these things to the return collection. tempItemViewModel.ListOfResponses.Add(tempString1); tempItemViewModel.ListOfResponses.Add(tempString2); //_context.Quotes.Add(quote); //await _context.SaveChangesAsync(); //return CreatedAtAction("GetQuote", new { id = quote.QuoteId }, quote); return(tempItemViewModel); }
public async Task <ActionResult <QuoteCubeCollection> > GetAllQuotes() { OptionsCollectionOfQuotes optionsCollectionOfQuotes = new OptionsCollectionOfQuotes(); IQuoteCubeCollection quoteCubeCollection = new ReturnQuoteCubeCollection(); //set up collection options. optionsCollectionOfQuotes.enumSourceOfData = EnumSourceOfData.DataBaseInContext; optionsCollectionOfQuotes.bloggingContext = _context; var tempCubeCollection = await quoteCubeCollection.GetQuoteCubeCollection(optionsCollectionOfQuotes); var generalAPIResponse = new GeneralAPIResponse { dateTimeOfResponse = DateTime.Now }; tempCubeCollection.generalAPIResponse = generalAPIResponse; return(tempCubeCollection); }
public ActionResult <GeneralAPIResponse> ServerDetailsHi() { var generalAPIResponse = new GeneralAPIResponse(); var tempString1 = "This is a Self Contained API Server"; var tempString2 = "It has its own local SQLite database"; var tempString3 = "It uses EF Core so you can modify the database from code as it pleases you"; var tempString4 = "Docker is configured."; var tempString5 = "Project Started on September 23rd 2020"; var tempString6 = "Contact the developer at [email protected]"; //lets add all these things to the return collection. generalAPIResponse.ListOfResponses.Add(tempString1); generalAPIResponse.ListOfResponses.Add(tempString2); generalAPIResponse.ListOfResponses.Add(tempString3); generalAPIResponse.ListOfResponses.Add(tempString4); generalAPIResponse.ListOfResponses.Add(tempString5); generalAPIResponse.ListOfResponses.Add(tempString6); generalAPIResponse.dateTimeOfResponse = DateTime.Now; return(generalAPIResponse); }
public async Task <ActionResult <QuoteCube> > GetASingleQuoteAsync() { var tempQuoteCube = new QuoteCube(); IReturnSingleQuote returnSingleQuote = new ReturnSingleQuote(); OptionsSingleQuote optionsSingleQuote = new OptionsSingleQuote(); //setting options optionsSingleQuote.enumSourceOfData = EnumSourceOfData.DataBaseInContext; //quote is random optionsSingleQuote.RandomQuote = true; //set the context. optionsSingleQuote.bloggingContext = _context; tempQuoteCube = await returnSingleQuote.ReturnASingleQuote(optionsSingleQuote); //add the general response var generalAPIResponse = new GeneralAPIResponse(); generalAPIResponse.dateTimeOfResponse = DateTime.Now; tempQuoteCube.generalAPIResponse = generalAPIResponse; return(tempQuoteCube); }
private async Task <List <QuoteCube> > SimpleCollectionOfQuoteCubesFromContext(OptionsCollectionOfQuotes optionsCollectionOfQuotes) { //at this point, I am assuming that the context is already checked for //dude, we cannot just send the entire 1000s of quotes. var limitOfQuotes = 100; var tempListOriginal = optionsCollectionOfQuotes.bloggingContext.QuoteModels.ToList().Take(limitOfQuotes); var tempList = new List <QuoteCube>(); //the database tables use the schema tables //my API uses JSON classes that are separate from the schema classes //this is the conversion happening //TODO - can we move this to a interface + class that does the conversion? foreach (var x in tempListOriginal) { var tempQuoteCube = new QuoteCube { QuoteContent = x.QuoteContent, QuoteIdentifierCompadre = x.QuoteId.ToString(), QuoteAuthor = x.QuoteAuthor, QuoteIdentifierString = x.QuoteIdentifierString }; var generalAPIResponse = new GeneralAPIResponse { dateTimeOfResponse = DateTime.Now }; tempQuoteCube.generalAPIResponse = generalAPIResponse; tempList.Add(tempQuoteCube); } //here, adding this await because, I am using an async Task based interface. //this being a memory based implementation, it does not actually have to wait for anything. //so, just wrapping this simple result in a task to avoid getting 'lack of async' error. return(await Task.FromResult(tempList)); }