public static List<Location> GetAllTracks() { using (ReviewsDataContext context = new ReviewsDataContext()) { var list = (from track in context.Tracks where track.Approved select new Location { Approved = true, City = track.City, Details = track.Details, Id = track.TrackId, Lat = track.Lat, Lon = track.Long, Name = track.Name, State = track.State, StreetAddress = track.StreetAddress, SubmittedBy = track.SubmittedBy, Url = track.TrackWebsite, Zip = track.ZipCode, TrackLength = track.TrackLength.HasValue ? track.TrackLength.Value : -1 }).ToList(); return list; } }
public static Location GetTrackById(int id, string user) { using (ReviewsDataContext context = new ReviewsDataContext()) { var trackDetails = (from track in context.Tracks where (track.Approved || String.Equals(track.SubmittedBy,user))&& track.TrackId== id select new Location { Approved = true, City = track.City, Details = track.Details, Id = track.TrackId, Lat = track.Lat, Lon = track.Long, Name = track.Name, State = track.State, StreetAddress = track.StreetAddress, SubmittedBy = track.SubmittedBy, Url = track.TrackWebsite, Zip = track.ZipCode, TrackLength = track.TrackLength.HasValue ? track.TrackLength.Value : -1, VisibleToUser = track.SubmittedBy.Equals(user) || track.Approved, }).FirstOrDefault(); return trackDetails; } }
public static List<ProductViewModel> AllUnapprovedMotorcycles() { using (ReviewsDataContext context = new ReviewsDataContext()) { List<ProductViewModel> unapprovedMotorcycles = (from product in context.Products join motor in context.Motorcycles on product.ProductId equals motor.ProductId where !product.Approved && product.Category.Equals(Constants.DatabaseConstants.DatabaseConstants.CategoryConstantStrings[Constants.DatabaseConstants.DatabaseConstants.CategoryConstants.MOTORCYCLES]) select new ProductViewModel { ProductBrand = product.Brand, ProductDescription = product.Description, ProductImage = product.Image, ProductTitle = product.Title, ProductId = product.ProductId, IsMotorcycle = true, SubmittedBy = product.SubmittedBy, Subcategory = product.SubCategory, Displacement = motor.Displacement.ToString(), Gears = motor.Gears.Value, TopSpeed = motor.TopSpeed.Value, Torque = motor.Torque.Value, EngineType = motor.EngineType, SiteUrl = product.SiteUrl }).ToList(); return unapprovedMotorcycles; } }
public static void CreateUser(User dbUserModel) { using (ReviewsDataContext context = new ReviewsDataContext()) { context.Users.InsertOnSubmit(dbUserModel); //.InsertAllOnSubmit(dbUserModel); context.SubmitChanges(); } }
public static void AddNewTrackReview(TrackReview dbNewReview) { using (ReviewsDataContext context = new ReviewsDataContext()) { dbNewReview.DatePosted = DateTime.Now; context.TrackReviews.InsertOnSubmit(dbNewReview); //.InsertAllOnSubmit(dbUserModel); context.SubmitChanges(); } }
public static int AddNewMotorcycle( Motorcycle dbMotorcycle) { using (ReviewsDataContext context = new ReviewsDataContext()) { context.Motorcycles.InsertOnSubmit(dbMotorcycle); //.InsertAllOnSubmit(dbUserModel); context.SubmitChanges(); return dbMotorcycle.MotorcycleId; } }
public static int AddTrack(Data.Track loc) { using(ReviewsDataContext context = new ReviewsDataContext()) { context.Tracks.InsertOnSubmit(loc); context.SubmitChanges(); return loc.TrackId; } }
public static int AddNewGearProduct(Product dbProduct) { using (ReviewsDataContext context = new ReviewsDataContext()) { context.Products.InsertOnSubmit(dbProduct); //.InsertAllOnSubmit(dbUserModel); context.SubmitChanges(); return dbProduct.ProductId; } }
public static Data.User GetUser(string userName) { using (ReviewsDataContext context = new ReviewsDataContext()) { Data.User user = (from u in context.Users where u.UserName.Equals(userName) select u).FirstOrDefault(); return user; } }
//private static UsersDataContext _context; //private static UsersDataContext Context //{ // get // { // if (_context == null) // { // _context = new UsersDataContext(); // } // return _context; // } //} public static bool UserExists(string userName) { using (ReviewsDataContext context = new ReviewsDataContext ()) { var allUsersWithName = (from u in context.Users where u.UserName.Equals(userName) select u); return allUsersWithName.ToList().Count() > 0; } }
protected void Button1_Click(object sender, EventArgs e) { var ctx = new ReviewsDataContext(); var newReview = new Review() { MovieId = "Thriller-Terminator 123", Reviewer = GetRandomString(5), Rating = RatingEnum.Awful, Text = "blah-blah" }; ctx.Reviews.InsertOnSubmit(newReview); ctx.SubmitChanges(); }
public static List<ReviewViewModel> GetAllReviewsForPage(int id) { List<ReviewViewModel> list = new List<ReviewViewModel>(); using (ReviewsDataContext context = new ReviewsDataContext()) { list = (from review in context.Reviews join user in context.Users on review.UserId equals user.UserName join product in context.Products on review.ProductId equals product.ProductId where review.ProductId == id select new ReviewViewModel { User = user.UserName, UserMotorcycle = user.CurrentMotorcycle, Rating = review.StarRating, ReviewText = review.Review1, LengthOfUse = review.LengthOfUse, PostedDateStr = review.DatePosted.ToShortDateString() }).ToList(); return list; } }
protected void Button2_Click(object sender, EventArgs e) { var ctx = new ReviewsDataContext(); foreach (var g in ctx.Genres) { Debug.WriteLine(g.IgnoredField); } foreach (var r in ctx.Reviewers) { Debug.WriteLine(r.Login); } ctx.Reviewers.InsertOnSubmit(new Reviewer() { Login = GetRandomString(5) }); ctx.SubmitChanges(); }
public static List<ProductViewModel> AllUnapprovedGear() { using (ReviewsDataContext context = new ReviewsDataContext()) { List<ProductViewModel> unapprovedGear = (from product in context.Products where !product.Approved && product.Category.Equals(Constants.DatabaseConstants.DatabaseConstants.CategoryConstantStrings[Constants.DatabaseConstants.DatabaseConstants.CategoryConstants.GEAR]) select new ProductViewModel { ProductBrand = product.Brand, ProductDescription = product.Description, ProductImage = product.Image, ProductTitle = product.Title, ProductId = product.ProductId, SubmittedBy = product.SubmittedBy, Subcategory = product.SubCategory, SiteUrl = product.SiteUrl, IsGear = true }).ToList(); return unapprovedGear; } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddAuthorization(options => { options.AddPolicy("ClientPolicy", p => p.RequireClaim("client_ClientType")); }); services.AddMvc(config => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); config.Filters.Add(new AuthorizeFilter(policy)); }); ReviewsDataContext dataCtx = new ReviewsDataContext(Configuration.GetConnectionString("ReviewsDataStore")); services.AddSingleton(dataCtx); //ReviewsStoreMongo store = new ReviewsStoreMongo(dataCtx); //services.AddSingleton(store); services.AddSingleton <IReviewsStore, ReviewsStoreMongo>(); }
public static List<ReviewViewModel> GetAllTrackReviewsForPage(int id) { List<ReviewViewModel> list = new List<ReviewViewModel>(); using (ReviewsDataContext context = new ReviewsDataContext()) { list = (from review in context.TrackReviews join user in context.Users on review.UserId equals user.UserName join track in context.Tracks on review.TrackId equals track.TrackId where review.TrackId == id select new ReviewViewModel { User = user.UserName, UserMotorcycle = user.CurrentMotorcycle, Rating = review.StarRating, ReviewText = review.Review, NumberOfVisits = review.NumberOfVisits.HasValue ? review.NumberOfVisits.Value: 0, PostedDateStr = review.DatePosted.ToShortDateString() }).ToList(); return list; } }
public static void CalculateReviewAverages() { using (ReviewsDataContext context = new ReviewsDataContext()) { var allProducts = (from product in context.Products select product); var allReviews = (from review in context.Reviews select new { ProductId= review.ProductId, Review =review.StarRating }); foreach (var p in allProducts) { if(allReviews.Any(x=> x.ProductId == p.ProductId)){ p.AverageRating = allReviews.Where(x => x.ProductId == p.ProductId).Average(x => Convert.ToDouble(x.Review)); } } context.SubmitChanges(); } }
public static List<Location> AllUnapprovedTracks() { using (ReviewsDataContext context = new ReviewsDataContext()) { List<Location> locations = (from track in context.Tracks where !track.Approved select new Location { City = track.City, State = track.State, Name = track.Name, Details = track.Details, StreetAddress = track.StreetAddress, SubmittedBy = track.SubmittedBy, Id= track.TrackId, Url = track.TrackWebsite, TrackLength = track.TrackLength.Value, Zip = track.ZipCode, }).ToList(); return locations; } }
public static List<string> GetAllBrands(string category) { using (ReviewsDataContext context = new ReviewsDataContext()) { return (from product in context.Products where product.Approved && product.Category.Equals(category) select product.Brand).Distinct().ToList(); } }
public static Models.ViewModels.Product.CategoryAndBrandModel GetAllFacetsForCategory(string category) { using (ReviewsDataContext context = new ReviewsDataContext()) { ///Make new linq to sql class for producs List<string> brands = (from product in context.Products where String.Equals(product.Category, category) select product.Brand).Distinct().ToList(); List<string> subcategories = (from product in context.Products where String.Equals(product.Category, category) && product.Approved select product.SubCategory).Distinct().ToList(); brands.Sort(); subcategories.Sort(); return new Models.ViewModels.Product.CategoryAndBrandModel { Subcategories = subcategories.Distinct(StringComparer.CurrentCultureIgnoreCase).ToList(), Brands = brands.Distinct(StringComparer.CurrentCultureIgnoreCase).ToList() }; } }
public static List<Product> GetFilteredProducts(string category, string brand, string subcategory) { using (ReviewsDataContext context = new ReviewsDataContext()) { List<Product> products = (from product in context.Products where product.Approved && String.Equals(product.Category.ToLower(), category.ToLower()) && (String.IsNullOrEmpty(brand) || String.Equals(brand.ToLower(), product.Brand.ToLower())) && (String.IsNullOrEmpty(subcategory) || string.Equals(subcategory, product.SubCategory.ToLower())) select product).OrderBy(x => x.Brand).OrderBy(x => x.Title).ToList(); return products; } }
public static ProductViewModel GetProductInfo(int id, string user) { using (ReviewsDataContext context = new ReviewsDataContext()) { var productInfo = (from product in context.Products where product.ProductId == id select product).FirstOrDefault(); ProductViewModel model = new ProductViewModel { ProductTitle = productInfo.Title, ProductImage = productInfo.Image, ProductId = productInfo.ProductId, ProductBrand = productInfo.Brand, ProductDescription = productInfo.Description, SubmittedBy = productInfo.SubmittedBy, IsApproved = productInfo.Approved, VisibleToUser = productInfo.SubmittedBy.Equals(user) || productInfo.Approved, IsAccessory = String.Equals(DatabaseConstants.CategoryConstantStrings[DatabaseConstants.CategoryConstants.ACCESSORIES],productInfo.Category,StringComparison.OrdinalIgnoreCase), IsGear = String.Equals(DatabaseConstants.CategoryConstantStrings[DatabaseConstants.CategoryConstants.GEAR],productInfo.Category,StringComparison.OrdinalIgnoreCase), IsMotorcycle = String.Equals(DatabaseConstants.CategoryConstantStrings[DatabaseConstants.CategoryConstants.MOTORCYCLES],productInfo.Category,StringComparison.OrdinalIgnoreCase) }; if (model.IsMotorcycle) { var motorcycleInfo = (from moto in context.Motorcycles where moto.ProductId == id select moto).FirstOrDefault(); if (motorcycleInfo != null) { model.Displacement = motorcycleInfo.Displacement != null ? motorcycleInfo.Displacement.ToString() : "0"; model.TopSpeed = motorcycleInfo.TopSpeed.HasValue ? motorcycleInfo.TopSpeed.Value : 0; model.Torque = motorcycleInfo.Torque.HasValue ? motorcycleInfo.Torque.Value : 0; model.Gears = motorcycleInfo.Gears.HasValue ? motorcycleInfo.Gears.Value : 0; } } return model; } }
public ReviewRepository(ReviewsDataContext context) : base(context) { }
public static List<Product> GetAllBrandsAndTypesForCategory(string category) { using (ReviewsDataContext context = new ReviewsDataContext()) { ///Make new linq to sql class for producs List<Product> products = (from product in context.Products where String.Equals(product.Category, category) && product.Approved select product).ToList(); return products; } }
public static int DuplicateProductExists(Product dbProduct) { using (ReviewsDataContext context = new ReviewsDataContext()) { Product p = (from product in context.Products where IsDuplicate(product, dbProduct) && product.Approved select product).FirstOrDefault(); if (p == null) { return -99;// no duplicat found feel free to insert } return p.ProductId; // duplicate found make suggestion to user.... allow them to ignore notification } }
public static bool HasUserReviewedTrack(int id, string userId) { using (ReviewsDataContext context = new ReviewsDataContext()) { var x = (from review in context.TrackReviews where review.TrackId == id && string.Equals(review.UserId, userId) select review).ToList(); return x.Count > 0; } }
public ReviewsStoreMongo(ReviewsDataContext ctx) { _dc = ctx; }
protected Repository(ReviewsDataContext context) { _context = context; }