private void AddRequestDocuments(int numberToAdd) { for (var idx = 0; idx < numberToAdd; idx++) { var request = DomainTypesFactory.Instance.CreateAccountRequest(); request.Submit(); var requestDocument = RequestDocumentFactory.Create(request, Commands.Submit); _context.Add(requestDocument); } _context.SaveChanges(); }
public IActionResult CreateUserRequest(Request request) { // Process, make API calls, add to DB if (ModelState.IsValid) { var wrapper = new CoreTweetWrapper(); var manager = new RequestManager(); var score = 0.0; var tweetList = wrapper.GetUserTimeline(request.TwitterHandle, request.Count).Result; var responses = manager.MakeRequest(tweetList.ToList()).Result; if (responses != null) { var json = (JObject)JsonConvert.DeserializeObject(responses); var documents = json.SelectToken("documents"); // Error in the request if (documents == null) { return(View("Error")); } // Access each document and sum the score token for (var i = 0; i < documents.Count(); i++) { var val = documents[i].SelectToken("score"); score += Convert.ToDouble(val.ToString()); } } request.Result = score / tweetList.Count; db.Add(request); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
public bool AddRequest(RequestViewModel requestView) { if (requestView != null) { Requests requests = new Requests() { ResquestName = requestView.ResquestName, StartDate = requestView.StartDate, FinishDate = requestView.FinishDate, Amount = requestView.Amount, Price = requestView.Price, Deleted = false, ContentName = requestView.ContentName, Note = requestView.Note, StateId = 1, UserId = requestView.UserId }; _context.Add(requests); } return(_context.SaveChanges() > 0 ? true : false); }