public async Task <IActionResult> Edit(int id, [Bind("Id,Address,FoodName,PicturesPath,Rating")] NewFoodTable newFoodTable) { if (id != newFoodTable.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(newFoodTable); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NewFoodTableExists(newFoodTable.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(newFoodTable)); }
public void search() { NewFoodTable table = new NewFoodTable(); //var query = from m in context.newFoodTable // select m; //if(query == null) //{ // Console.WriteLine("Query is null"); //} //IQueryable<string> foodQuery = from m in context.newFoodTable // orderby m.FoodName // select m.FoodName; var FoodList = new NewFoodTable(); List <NewFoodTable> foodList = new List <NewFoodTable>(); List <ApplicationUser> users = new List <ApplicationUser>(); //foodList = query.ToList(); //users = query.ToList(); foreach (ApplicationUser F in users) { // Console.WriteLine("The name is " + F.UserName); } }
public List <NewReviews> getFoodReviews(NewFoodTable place) { var freviews = from r in _context.newReviews where r.Id == place.Id select r; return(freviews.ToList()); }
public async Task <IActionResult> Create([Bind("Id,Address,FoodName,PicturesPath,Rating")] NewFoodTable newFoodTable) { if (ModelState.IsValid) { _context.Add(newFoodTable); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(newFoodTable)); }
public void Create2([Bind("Id,Address,FoodName,PicturesPath,Rating")] NewFoodTable newFoodTable) { Console.WriteLine("The Object:"); Console.WriteLine("Name: " + newFoodTable.FoodName + " Address: " + newFoodTable.Address + " Rating:" + newFoodTable.Rating.ToString() + "Picture: " + newFoodTable.PicturesPath); newFoodTable.Rating = Math.Ceiling(newFoodTable.Rating); if (ModelState.IsValid) { _context.Add(newFoodTable); _context.SaveChanges(); Console.WriteLine("Added"); } }
public void SearchandGet(NewFoodTable searchstring, string content) { //Task<ApplicationUser> user = GetCurrentUserAsync(); //Console.WriteLine("The id of the current user " + user.Id); var place = from p in _context.newFoodTable select p; place = place.Where(p => p.FoodName.Contains(searchstring.FoodName)); NewFoodTable foundplace = place.First(); //If the search query string is not empty if (!String.IsNullOrEmpty(searchstring.FoodName)) { //Search for the place in the database Console.WriteLine("Searching for " + foundplace.Id + " in reviews" + foundplace.FoodName); var allreviews = from r in _context.newReviews where r.newFoodTable.Id == foundplace.Id select r; //No Reviews were found if (allreviews.Count() == 0) { Console.WriteLine("Not Found"); //r //Create2(searchstring); } //Get the reviews from the database else { Console.WriteLine("Found"); List <NewReviews> pReviews = allreviews.ToList(); foreach (NewReviews r in pReviews) { Console.WriteLine("The review " + r.Review1); } } } }
public NewFoodTable findPlace(NewFoodTable table) { //Check to see if the database contains the place var dplace = from p in _context.newFoodTable where p.FoodName == table.FoodName select p; NewFoodTable foundplace; //If not make the place if (dplace.Count() == 0) { NewFoodTable newplace = table; _context.Add(newplace); foundplace = newplace; return(foundplace); } else { foundplace = dplace.First(); return(foundplace); } }
public void Search(NewFoodTable searchstring) { var places = from p in _context.newFoodTable select p; Console.WriteLine("Something: " + searchstring.FoodName + " Rating: " + searchstring.Rating); if (!String.IsNullOrEmpty(searchstring.FoodName)) { places = places.Where(p => p.FoodName.Contains(searchstring.FoodName)); if (places.Count() == 0) { Create2(searchstring); } foreach (NewFoodTable table in places) { Console.WriteLine(table.FoodName); } } }
public List <ReturnedReview> getReviews2(NewFoodTable table) { if (ModelState.IsValid) { Dictionary <int, ReturnedReview> myReplyHolder = new Dictionary <int, ReturnedReview>(); //Check to see if the database contains the place var dplace = from p in _context.newFoodTable where p.FoodName == table.FoodName select p; NewFoodTable foundplace; //If not make the place if (dplace.Count() == 0) { NewFoodTable newplace = table; _context.Add(newplace); foundplace = newplace; } else { foundplace = dplace.First(); } var nReviews = from r in _context.newReviews join f2 in _context.newFoodTable on r.newFoodTable.Id equals f2.Id join f3 in _context.newReviewReply on r.Id equals f3.newReview.Id into myList from x in myList.DefaultIfEmpty() where f2.FoodName == foundplace.FoodName select new { r.Review1, r.Id, r.newUser.UserName, r.ReviewDate, r.Like, f2.FoodName, ReplyId = (x == null ? 0 : x.Id), Reply = (x == null ? String.Empty : x.reply), ReplyUser = (x == null ? String.Empty : x.newUser.UserName) }; List <ReturnedReview> newList = new List <ReturnedReview>(); foreach (var item in nReviews.ToList()) { Console.WriteLine("FoodName: " + item.FoodName + " User " + item.UserName + " Review " + item.Review1); Console.WriteLine("Reply Id" + item.ReplyId); ReturnedReview thisReview = new ReturnedReview(); thisReview.FoodName = item.FoodName; thisReview.rContents = item.Review1; thisReview.Username = item.UserName; thisReview.rLike = item.Like; thisReview.rId = item.Id; thisReview.rDate = item.ReviewDate.ToString(); if (item.ReplyId != 0) { if (myReplyHolder.ContainsKey(item.Id)) { Console.WriteLine("Found the key"); Console.WriteLine("The Review " + item.Review1); ReturnedReview foundReply = myReplyHolder[item.Id]; ReturnedReply uReply = new ReturnedReply(); uReply.user = item.ReplyUser; uReply.rpContents = item.Reply; thisReview.rpList = new List <ReturnedReply>(); thisReview.rpList.Add(uReply); foundReply.rpList.Add(uReply); foreach (var reply in foundReply.rpList) { Console.WriteLine("The Replies so far " + reply.rpContents); } } else { Console.WriteLine("Adding new key"); ReturnedReply uReply = new ReturnedReply(); uReply.user = item.ReplyUser; uReply.rpContents = item.Reply; thisReview.rpList = new List <ReturnedReply>(); thisReview.rpList.Add(uReply); Console.WriteLine(uReply.rpContents); myReplyHolder.Add(item.Id, thisReview); } } else { newList.Add(thisReview); } } foreach (var repItem in myReplyHolder) { Console.WriteLine("Adding Review with Replies to List"); newList.Add(repItem.Value); } return(newList); } else { List <ReturnedReview> emptyList = new List <ReturnedReview>(); return(emptyList); } }
public async Task <List <NewReviews> > makeUserReview(NewFoodTable place, string content, string date, bool like, string captcha) { await IsValidCaptcha(captcha); if (ModelState.IsValid) { Console.WriteLine("The Review " + content); //Console.WriteLine("The Review like " + like); Console.WriteLine("The Review Date" + date); CultureInfo eng = new CultureInfo("en-US"); DateTime newDate = DateTime.Parse(date); Console.WriteLine("New Review Date " + newDate); //Check to see if the database contains the place var dplace = from p in _context.newFoodTable where p.FoodName == place.FoodName select p; NewFoodTable foundplace; //If not make the place if (dplace.Count() == 0) { NewFoodTable newplace = place; _context.Add(newplace); foundplace = newplace; } else { foundplace = dplace.First(); } //Gets the Current User var user = getUser().Result; //Create a new review NewReviews review = new NewReviews(); review.Review1 = content; review.newUser = user; review.newFoodTable = foundplace; review.ReviewDate = newDate; review.Like = like; //Add it to the database _context.Add(review); await _context.SaveChangesAsync(); return(getFoodReviews(review.newFoodTable)); } else { Console.WriteLine("Model State was not valid!"); Console.WriteLine(place.FoodName); Console.WriteLine(place.Address); Console.WriteLine(place.PicturesPath); Console.WriteLine(place.Rating); Console.WriteLine("The Review " + content); //Console.WriteLine("The Review like " + like); Console.WriteLine("The Review Date" + date); DateTime newDate = DateTime.Parse(date); Console.WriteLine("New Review Date " + newDate); return(getFoodReviews(place)); } }