public IActionResult EditReview([FromBody] EditReview args) { var review = _context.Reviews.SingleOrDefault(o => o.GameId == args.GameId && o.UserId == args.UserId); if (review == null) { _context.Reviews.Add( new Review { GameId = args.GameId, UserId = args.UserId, Score = args.Score, Details = args.Details } ); _context.SaveChanges(); return(new JsonResult(new { Status = "Added", ScoreChange = 0 })); } else { var oldScore = review.Score; review.Score = args.Score; review.Details = args.Details; _context.SaveChanges(); return(new JsonResult(new { Status = "Edited", ScoreChange = review.Score - oldScore })); } }
public ActionResult Create(ToReviewEntity toreviewentity) { if (ModelState.IsValid) { db.ReviewEntity.Add(toreviewentity); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(toreviewentity)); }
public async Task GetItemReturnsItem() { var options = new DbContextOptionsBuilder <ReviewsContext>() .UseInMemoryDatabase(databaseName: $"ItemsDatabase{Guid.NewGuid()}") .Options; using (var context = new ReviewsContext(options)) { context.Items.Add(new Item { Name = "item" }); context.Items.Add(new Item { Name = "item1" }); context.SaveChanges(); } using (var context = new ReviewsContext(options)) { ItemRepository repo = new ItemRepository(context); var _controller = new ItemsController(repo, _mockLogger.Object); var okResult = await _controller.GetItem("item") as OkObjectResult; Assert.Equal(200, okResult.StatusCode); } }
public IActionResult PostUser([FromBody] PostUser args) { if (_context.Users.Any(o => o.UserName == args.UserName)) { return(null); } else { var newUser = new User { UserName = args.UserName }; _context.Users.Add(newUser); _context.SaveChanges(); return(new JsonResult(new { newUser.UserId, newUser.UserName })); } }
public async Task GetReviewsWithLowerRatingReturnsReviews() { var options = new DbContextOptionsBuilder <ReviewsContext>() .UseInMemoryDatabase(databaseName: $"ItemsDatabase{Guid.NewGuid()}") .Options; using (var context = new ReviewsContext(options)) { context.Items.Add(new Item { Name = "item", Reviews = new List <Review>() { new Review { Feedback = "smth", Rating = 3 } } }); context.SaveChanges(); } using (var context = new ReviewsContext(options)) { ItemRepository repo = new ItemRepository(context); var _controller = new ReviewsController(repo, _mockLogger.Object, _mapper.Object); var okResult = await _controller.GetReviewByAverageRatingLowerThan(2) as OkObjectResult; Assert.Equal(200, okResult.StatusCode); } }
public IActionResult Create(UserReview nr) { if (ModelState.IsValid) { UserReview NewUserReview = new UserReview { Reviewer = nr.Reviewer, Restaurants = nr.Restaurants, Review = nr.Review, Visit = nr.Visit, Stars = nr.Stars, }; if (nr.Visit > DateTime.Now) { TempData["InvalidDate"] = "Date has to be before todays date"; } else { _context.Add(NewUserReview); _context.SaveChanges(); return(RedirectToAction("Reviews")); } } return(RedirectToAction("Index")); }
public bool createReview() { using (var dbTransaction = db.Database.BeginTransaction()) { try { Review rev = new Review { UserID = 1, RevieweeID = 2, Rating = 3, ReviewMessage = "test", DateAndTime = new DateTime(2015, 12, 12) }; db.Review.Add(rev); db.SaveChanges(); dbTransaction.Commit(); return(true); } catch (SqlException) { dbTransaction.Rollback(); return(false); } catch (DataException) { dbTransaction.Rollback(); return(false); } } }
public async Task LeaveReviewAsync(string name, Review review) { var item = _context.Items.Where(i => i.Name.ToLower() == name.ToLower()).FirstOrDefault(); await Task.Run(() => item.Reviews.Add(review)); _context.SaveChanges(); }
public IActionResult AddReview(RegisterViewModels NewReview) { if (ModelState.IsValid) { _context.Reviews.Add(NewReview); _context.SaveChanges(); return(RedirectToAction("Reviews")); } return(View("Index")); }
//Add Review into the database public bool AddReview(ReviewsDTO obj) { //begins transaction between linq and sql using (var dbTransaction = db.Database.BeginTransaction()) { try { //Gets userID based off of username based on credentials int getUserID = (from cred in db.Credentials where obj.Username == cred.UserName select cred.UserID).FirstOrDefault(); int getTargetUserID = (from cred in db.Credentials where obj.TargetUser == cred.UserName select cred.UserID).FirstOrDefault(); //ReviewID is a key and will be automatically incremented //creates a new review instance by grabbing object's data from client Review r = new Review { UserID = getTargetUserID, RevieweeID = getUserID, Rating = obj.Rating, ReviewMessage = obj.ReviewMessage, DateAndTime = obj.DateAndTime, }; //add the new instance and saves into database db.Review.Add(r); db.SaveChanges(); dbTransaction.Commit(); return(true); } catch (SqlException) { dbTransaction.Rollback(); return(false); }/* * catch (DataException) * { * dbTransaction.Rollback(); * return false; * } */ } }
public void ItemExsitsReturnsTrue() { var options = new DbContextOptionsBuilder <ReviewsContext>() .UseInMemoryDatabase(databaseName: $"ItemsDatabase{Guid.NewGuid()}") .Options; using (var context = new ReviewsContext(options)) { context.Items.Add(new Item { Name = "item", Reviews = new List <Review>() { new Review { Feedback = "smth", Rating = 10 } } }); context.SaveChanges(); IItemRepository repo = new ItemRepository(context); var result = repo.ItemExists("item"); Assert.True(result); } }
public ActionResult FacebookCallback2(fbuser user) { ReviewsContext db = new ReviewsContext(); user.id = iduserG; db.Users.Attach(user); foreach (var item in user.pagelist) { db.Pages.Attach(item); db.Entry(item).State = EntityState.Modified; } //user.id = 10213618568591702+""; db.Entry(user).State = EntityState.Modified; fuserG = user; db.SaveChanges(); return(RedirectToAction("FacebookCallback3", "Home")); }
public async Task GetReviewByNameReturnsItem() { var options = new DbContextOptionsBuilder <ReviewsContext>() .UseInMemoryDatabase(databaseName: $"ItemsDatabase{Guid.NewGuid()}") .Options; using (var context = new ReviewsContext(options)) { context.Items.Add(new Item { Name = "item", Reviews = new List <Review>() { new Review { Feedback = "smth", Rating = 10 } } }); context.SaveChanges(); IItemRepository repo = new ItemRepository(context); var result = await repo.GetReviewsByItemNameAsync("item"); Assert.Single(result); } }
public async Task CreatesReviewForItem() { var options = new DbContextOptionsBuilder <ReviewsContext>() .UseInMemoryDatabase(databaseName: $"ItemsDatabase{Guid.NewGuid()}") .Options; using (var context = new ReviewsContext(options)) { var review = new Review { Feedback = "smth", Rating = 10 }; context.Items.Add(new Item { Name = "item" }); context.SaveChanges(); IItemRepository repo = new ItemRepository(context); await repo.LeaveReviewAsync("item", review); var reviewFromItem = await repo.GetReviewsByItemNameAsync("item"); Assert.Single(reviewFromItem); } }
public void Create(UserReview userReview) { db.UserReviews.Add(userReview); db.SaveChanges(); }
public ActionResult FacebookCallback(string code) { var fb = new FacebookClient(); dynamic result = fb.Post("oauth/access_token", new { client_id = "2253354658274452", client_secret = "35cf0272817393adb4c8d253f5dbe7ad", redirect_uri = RediredtUri.AbsoluteUri, code = code }); var accessToken = result.access_token; var accesToken = result.access_token; //short lived acces Token dynamic result2 = fb.Get("https://graph.facebook.com/v3.0/oauth/access_token?grant_type=fb_exchange_token&client_id=2253354658274452&client_secret=35cf0272817393adb4c8d253f5dbe7ad&fb_exchange_token=" + accesToken); var accesToken2 = result2.access_token; // long lived acces Token Session["AccessToken"] = accesToken2; fb.AccessToken = accesToken2; dynamic me1 = fb.Get("me"); string iduser = me1.id; dynamic result3 = fb.Get(" https://graph.facebook.com/v3.0/me?fields=accounts&access_token" + accesToken2); var pages = result3.accounts.data; int length = pages.Count; /* string id = string.Empty; * for (int i = 0; i < length; i++) * { * if (pages[i] != null) * { id = pages[i].id; } * * } * * * dynamic result4 = fb.Get(" https://graph.facebook.com/v3.0/" + id + "?fields=access_token&access_token=" + accesToken2); * var accesTokenPage = result4.access_token; //page acces Token aves expiration=jamais * TempData["Page Acces Token"] = accesTokenPage; * Session["AccessToken"] = accesTokenPage; * fb.AccessToken = accesTokenPage; * * * * * * dynamic mee = fb.Get("me?id"); * dynamic me = fb.Get("me?id"); * * string email = me.email; * * TempData["email"] = me; */ var data = result3.accounts["data"].ToString(); var mm = JsonConvert.DeserializeObject <List <page> >(data); var f1 = new fbuser(); f1.id = iduser; f1.pagelist = mm; iduserG = iduser; /****/ ReviewsContext db = new ReviewsContext(); int abc = 0; if (db.Users.Find(f1.id) == null) { db.Users.Add(f1); abc = 1; } foreach (var item in f1.pagelist) { if (db.Pages.Find(item.id) == null) { db.Pages.Add(item); db.SaveChanges(); db.Database.ExecuteSqlCommand( "UPDATE dbo.Pages SET fbuser_id = " + iduser + "where id =" + item.id); } } db.SaveChanges(); /*****/ f1 = db.Users.Find(f1.id); fuserG = f1; if (abc == 1) { return(View(f1)); } return(RedirectToAction("FacebookCallback3", "Home")); // return Redirect("~/Home/Index"); }