public async Task <ActionResult> Edit(string Id) { if (string.IsNullOrEmpty(Id)) { return(RedirectToAction(nameof(Index))); } CVGSAppEntities db = new CVGSAppEntities(); try { var model = await db.Games.FindAsync(Id); if (model == null) { TempData["message"] = string.Format("Game record with {0} id was not found", Id); RedirectToAction(nameof(Index)); } var gameCategories = new SelectList(db.GameCategories.ToList(), "Id", "Name"); ViewData["GameCategories"] = gameCategories; var gamePlatforms = new SelectList(db.GamePlatforms.ToList(), "Id", "Name"); ViewData["GamePlatforms"] = gamePlatforms; return(View(model)); } catch { TempData["message"] = string.Format("Unexpected error occurred while updating a game (id = {0})", Id); return(RedirectToAction(nameof(Index))); } }
public JsonResult DeleteCreditCard(int?Id) { if (Id == null) { return(Json(new { Success = false, Error = "Information not received" }, JsonRequestBehavior.AllowGet)); } CVGSAppEntities db = new CVGSAppEntities(); try { var creditCard = db.CreditCards.FirstOrDefault(c => c.Id == Id); if (creditCard == null) { return(Json(new { Success = false, Error = "Credit Card not found" }, JsonRequestBehavior.AllowGet)); } db.CreditCards.Remove(creditCard); db.SaveChanges(); return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { Success = false, Error = "Error occurred while deleting credit card record" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Index() { CVGSAppEntities db = new CVGSAppEntities(); var userId = User.Identity.GetUserId(); List <string> gameIds = new List <string>(); IQueryable <Game> model = db.Games.Where(g => !string.IsNullOrEmpty(g.ImageUrl)); if (TempData.ContainsKey("SearchString")) { string searchString = (string)TempData["SearchString"]; if (!string.IsNullOrEmpty(searchString)) { model = model.Where(g => g.Title.ToLower().Contains(searchString.ToLower())); } } var categories = db.GameCategories.ToDictionary(item => item.Id, item => item.Name); var platforms = db.GamePlatforms.ToDictionary(item => item.Id, item => item.Name); foreach (Game game in model) { if (categories.Any()) { game.CategoryName = game.CategoryId == null ? "None" : categories[(int)game.CategoryId]; } if (platforms.Any()) { game.PlatformName = game.PlatformId == null ? "None" : platforms[(int)game.PlatformId]; } } return(View(model)); }
// // GET: /Manage/ChangeAccountDetails public async Task <ActionResult> ChangeAccountDetails() { var userId = User.Identity.GetUserId(); var memberUser = new MemberUser(); using (CVGSAppEntities db = new CVGSAppEntities()) { memberUser = db.MemberUsers.FirstOrDefault(m => m.Id == userId); } var categoryPrefs = (GameCategoryOptions)memberUser.CategoryOptions; var platformPrefs = (FavoritePlatforms)memberUser.PlatformOptions; var model = new UserViewModel { DisplayName = User.Identity.Name, Email = await UserManager.GetEmailAsync(userId), FirstName = memberUser.FirstName, LastName = memberUser.LastName, BirthDate = memberUser.BirthDate, Sex = memberUser.Sex == null ? 2 : (int)memberUser.Sex, ActionChecked = categoryPrefs.HasFlag(GameCategoryOptions.Action), AdventureChecked = categoryPrefs.HasFlag(GameCategoryOptions.Adventure), RolePlayingChecked = categoryPrefs.HasFlag(GameCategoryOptions.RolePlaying), SimulationChecked = categoryPrefs.HasFlag(GameCategoryOptions.Simulation), StrategyChecked = categoryPrefs.HasFlag(GameCategoryOptions.Strategy), PuzzleChecked = categoryPrefs.HasFlag(GameCategoryOptions.Puzzle), PCChecked = platformPrefs.HasFlag(FavoritePlatforms.PC), PlayStationChecked = platformPrefs.HasFlag(FavoritePlatforms.PlayStation), XboxChecked = platformPrefs.HasFlag(FavoritePlatforms.Xbox), NintendoChecked = platformPrefs.HasFlag(FavoritePlatforms.Nintendo), MobileChecked = platformPrefs.HasFlag(FavoritePlatforms.Mobile), SendPromotionalEmails = memberUser.SendPromotionalEmails == null ? false : (bool)memberUser.SendPromotionalEmails }; return(View(model)); }
public async Task <ActionResult> Create(Event newEvent) { var db = new CVGSAppEntities(); // Event name unique if (db.Events.Any(e => e.Title == newEvent.Title)) { ModelState.AddModelError("Title", "An event with this name already exists."); } ValidateEvent(newEvent); if (!ModelState.IsValid) { return(View(newEvent)); } try { newEvent.Id = Guid.NewGuid().ToString(); db.Events.Add(newEvent); await db.SaveChangesAsync(); TempData["message"] = $"Record for '{newEvent.Title}' successfully added"; return(RedirectToAction(nameof(Index))); } catch (Exception ex) { ModelState.AddModelError("", $"Error: {ex.GetBaseException().Message}"); return(View(newEvent)); } }
public JsonResult AddCreditCard(CreditCard creditCard) { // Validation? // TODO: format credit card number before saving // TODO: format expiration date info? creditCard.HolderId = User.Identity.GetUserId(); CVGSAppEntities db = new CVGSAppEntities(); try { // format credit card number string cardNumberFormatted = creditCard.CardNumber.Replace(" ", string.Empty); cardNumberFormatted = cardNumberFormatted.Length == 13 ? string.Format("{0:0000 0000 0000 0}", (long.Parse(cardNumberFormatted))) : cardNumberFormatted.Length == 15 ? string.Format("{0:0000 0000 0000 000}", (long.Parse(cardNumberFormatted))) : string.Format("{0:0000 0000 0000 0000}", (long.Parse(cardNumberFormatted))); creditCard.CardNumber = cardNumberFormatted; //save the card in the database db.CreditCards.Add(creditCard); db.SaveChanges(); return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { Success = false, Error = "Error occurred while saving card information" }, JsonRequestBehavior.AllowGet)); } }
public ReviewController() { if (db == null) { db = new CVGSAppEntities(); } }
public ReportController() { if (_db == null) { _db = new CVGSAppEntities(); } }
public ActionResult Orders() { CVGSAppEntities db = new CVGSAppEntities(); var userId = User.Identity.GetUserId(); var orders = db.Orders.Where(o => o.UserId == userId); var orderItems = db.OrderItems; var games = db.Games; List <OrdersViewModel> model = new List <OrdersViewModel>(); foreach (var order in orders) { var gameIds = db.OrderItems.Where(oi => oi.OrderId == order.Id).Select(oi => oi.GameId).ToList(); var orderGames = games.Where(g => gameIds.Contains(g.Id)); //decimal total = 0; var total = Math.Round(orderGames.Sum(g => g.Price) * (decimal)1.13, 2); List <GameThumbView> gameThumbs = orderGames.Select(g => new GameThumbView { Id = g.Id, ImageUrl = g.ImageUrl }).ToList(); model.Add(new OrdersViewModel { Id = order.Id, OrderPlaced = order.PurchaseDate, ItemNumber = orderItems.Where(oi => oi.OrderId == order.Id).Count(), Total = total, Games = gameThumbs }); } return(View(model)); }
public ActionResult ChangeAddressDetails() { // get user object from the storage var userId = User.Identity.GetUserId(); //var user = await UserManager.FindByIdAsync(userId); CVGSAppEntities db = new CVGSAppEntities(); var memberUser = db.MemberUsers.FirstOrDefault(m => m.Id == userId); var model = memberUser.MemberUserToAddressesViewModel(); //var provinces = new SelectList(db.Provinces.ToList(), "Code", "Name"); List <SelectListItem> provinces = db.Provinces .OrderBy(p => p.Name) .Select(p => new SelectListItem { Value = p.Code, Text = p.Name }).ToList(); provinces.Insert(0, new SelectListItem { Text = "", Value = "" }); ViewData["ProvinceList"] = provinces; return(View(model)); }
public JsonResult GetCreditCard(int?Id) { if (Id == null) { return(Json(new { Success = false, Error = "Information not received" }, JsonRequestBehavior.AllowGet)); } CVGSAppEntities db = new CVGSAppEntities(); try { var creditCard = db.CreditCards.Find(Id); if (creditCard == null) { return(Json(new { Success = false, Error = "Credit Card not found" }, JsonRequestBehavior.AllowGet)); } return(Json(creditCard, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { Success = false, Error = "Error occurred while retrieving credit card record" }, JsonRequestBehavior.AllowGet)); } }
private IQueryable <Game> GetPurchaseDGames(CVGSAppEntities db, string userId) { var orderIds = db.Orders.Where(o => o.UserId == userId).Select(o => o.Id).ToList(); var gameIds = db.OrderItems.Where(oi => orderIds.Contains(oi.OrderId)).Select(oi => oi.GameId).ToList(); IQueryable <Game> purchasedGames = db.Games.Where(g => gameIds.Contains(g.Id)); return(purchasedGames); }
protected void Session_Start(object sender, EventArgs e) { CVGSAppEntities db = new CVGSAppEntities(); var userId = User.Identity.GetUserId(); if (userId != null) { Session["cart"] = db.UserCartItems.Where(i => i.UserId == userId).Count().ToString(); } }
public ActionResult Create() { using (CVGSAppEntities db = new CVGSAppEntities()) { var gameCategories = new SelectList(db.GameCategories.ToList(), "Id", "Name"); ViewData["GameCategories"] = gameCategories; var gamePlatforms = new SelectList(db.GamePlatforms.ToList(), "Id", "Name"); ViewData["GamePlatforms"] = gamePlatforms; } return(View()); }
public JsonResult GetCreditCards() { string currentUserId = User.Identity.GetUserId(); List <CreditCard> creditCards = new List <CreditCard>(); using (CVGSAppEntities db = new CVGSAppEntities()) { creditCards = db.CreditCards.Where(c => c.HolderId == currentUserId).ToList(); } return(Json(creditCards, JsonRequestBehavior.AllowGet)); }
public JsonResult AutoComplete(string term) { CVGSAppEntities db = new CVGSAppEntities(); var games = db.Games.ToList(); if (!string.IsNullOrEmpty(term)) { games = games.Where(g => g.Title.ToLower().Contains(term.ToLower()) && !string.IsNullOrEmpty(g.ImageUrl)).ToList(); } var jsonGames = games.Select(g => new { label = g.Title, value = g.Id }).ToList(); return(Json(jsonGames, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> Edit(Event updatedEvent) { CVGSAppEntities db = new CVGSAppEntities(); if (updatedEvent == null || string.IsNullOrEmpty(updatedEvent.Id)) { return(RedirectToAction(nameof(Index))); } // Unqiue Name if (db.Events.Any(e => e.Title == updatedEvent.Title && e.Id != updatedEvent.Id)) { ModelState.AddModelError("Title", "An event with this name already exists."); } try { var existingEvent = await db.Events.FindAsync(updatedEvent.Id); if (existingEvent == null) { TempData["message"] = string.Format("Event record with {0} id was not found", updatedEvent.Id); RedirectToAction(nameof(Index)); } ValidateEvent(updatedEvent); if (!ModelState.IsValid) { return(View(updatedEvent)); } existingEvent.Title = updatedEvent.Title; existingEvent.Description = updatedEvent.Description; existingEvent.StartTime = updatedEvent.StartTime; existingEvent.EndTime = updatedEvent.EndTime; existingEvent.MaxAttendeeNumber = updatedEvent.MaxAttendeeNumber; existingEvent.IsIRL = updatedEvent.IsIRL; existingEvent.Location = updatedEvent.Location; await db.SaveChangesAsync(); TempData["message"] = $"Record for '{updatedEvent.Title}' successfully updated"; return(RedirectToAction(nameof(Index))); } catch { return(View(updatedEvent)); } }
public async Task <ActionResult> Create(Game model) { model.Rating = 0; CVGSAppEntities db = new CVGSAppEntities(); try { //Game name unique if (db.Games.Any(g => g.Title == model.Title)) { ModelState.AddModelError("Title", "A game with this name already exists."); } // Release Year is integer between 1985 and 2020 if (model.ReleaseYear != null) { if (model.ReleaseYear != (int)model.ReleaseYear) { ModelState.AddModelError("ReleaseYear", "The release year must be an integer."); } else if ((int)model.ReleaseYear < 1985 || (int)model.ReleaseYear > 2020) { ModelState.AddModelError("ReleaseYear", "The release year must be between 1985 and 2020."); } } if (!ModelState.IsValid) { var gameCategories = new SelectList(db.GameCategories.ToList(), "Id", "Name"); ViewData["GameCategories"] = gameCategories; var gamePlatforms = new SelectList(db.GamePlatforms.ToList(), "Id", "Name"); ViewData["GamePlatforms"] = gamePlatforms; return(View(model)); } model.Id = Guid.NewGuid().ToString(); db.Games.Add(model); await db.SaveChangesAsync(); TempData["message"] = $"Record for '{model.Title}' successfully added"; return(RedirectToAction(nameof(Index))); } catch (Exception ex) { ModelState.AddModelError("", $"Error: {ex.GetBaseException().Message}"); var gameCategories = new SelectList(db.GameCategories.ToList(), "Id", "Name"); ViewData["GameCategories"] = gameCategories; var gamePlatforms = new SelectList(db.GamePlatforms.ToList(), "Id", "Name"); ViewData["GamePlatforms"] = gamePlatforms; return(View(model)); } }
public ActionResult Unfriend(string id) { CVGSAppEntities db = new CVGSAppEntities(); var userId = User.Identity.GetUserId(); var friend = db.FriendLists.FirstOrDefault(f => f.userId == userId && f.friendId == id); if (friend != null) { db.FriendLists.Remove(friend); db.SaveChanges(); } return(RedirectToAction("FriendList", "Manage")); }
public ActionResult AddToFriendList(string id) { CVGSAppEntities db = new CVGSAppEntities(); var userId = User.Identity.GetUserId(); if (db.FriendLists.FirstOrDefault(f => f.userId == userId && f.friendId == id) == null) { db.FriendLists.Add(new FriendList { userId = userId, friendId = id }); db.SaveChanges(); } return(RedirectToAction("Details", new { id = id })); }
public ActionResult Index() { CVGSAppEntities db = new CVGSAppEntities(); var games = db.Games; var categories = db.GameCategories.ToDictionary(item => item.Id, item => item.Name); var platforms = db.GamePlatforms.ToDictionary(item => item.Id, item => item.Name); foreach (var game in games) { game.CategoryName = game.CategoryId == null ? "None" : categories[(int)game.CategoryId]; game.PlatformName = game.PlatformId == null ? "None" : platforms[(int)game.PlatformId]; } return(View(games.ToList())); }
//[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")] public ActionResult _ReviewListPartial(string Id) { // TODO: Validate ID! CVGSAppEntities db = new CVGSAppEntities(); var model = new ReviewListModel(); model.GameId = Id; // add approved reviews for the game var reviews = db.GameReviews.Where(r => r.GameId == Id && r.Approved == true); var approvedReviews = new List <ReviewViewModel>(); var applicationUserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); foreach (var review in reviews) { approvedReviews.Add(new ReviewViewModel { Id = review.Id, ReviewerId = review.CreatedBy, Reviewer = applicationUserManager.FindById(review.CreatedBy).UserName, EditedOn = review.EditedOn, ReviewText = review.ReviewText }); } model.ApprovedReviews = approvedReviews.OrderBy(m => m.EditedOn).ToList(); // add unapproved reviews for the game left by the current user var userId = User.Identity.GetUserId(); var userName = User.Identity.GetUserName(); var unapprovedReviews = db.GameReviews .Where(r => r.GameId == Id && r.CreatedBy == userId && r.Approved == false) .Select(r => new ReviewViewModel { Id = r.Id, ReviewerId = r.Id, Reviewer = userName, ReviewText = r.ReviewText, EditedOn = r.EditedOn }) .ToList(); model.UnapprovedReviewsByUser = unapprovedReviews.OrderBy(r => r.EditedOn).ToList(); return(PartialView(model)); }
public JsonResult DeleteReview(GameReview review) { CVGSAppEntities db = new CVGSAppEntities(); try { var memberId = User.Identity.GetUserId(); var savedReview = db.GameReviews.FirstOrDefault(r => r.Id == review.Id); db.GameReviews.Remove(savedReview); db.SaveChanges(); return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { Success = false, Error = "Error occurred while deleting review" }, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> Edit(string id) { if (string.IsNullOrEmpty(id)) { return(RedirectToAction(nameof(Index))); } CVGSAppEntities db = new CVGSAppEntities(); var model = await db.Events.FindAsync(id); if (model == null) { TempData["message"] = string.Format("Event record with {0} id was not found", id); RedirectToAction(nameof(Index)); } return(View(model)); }
public async Task <ActionResult> Delete(Event model) { CVGSAppEntities db = new CVGSAppEntities(); try { db.Events.Attach(model); db.Events.Remove(model); await db.SaveChangesAsync(); TempData["message"] = $"Record successfully deleted"; return(RedirectToAction(nameof(Index))); } catch (Exception ex) { ModelState.AddModelError("", $"Error: {ex.GetBaseException().Message}"); return(View(model)); } }
public JsonResult AddRating(GameRating newRating) { CVGSAppEntities db = new CVGSAppEntities(); var userId = User.Identity.GetUserId(); var existingRatingByUser = db.GameRatings.FirstOrDefault(rating => rating.GameId == newRating.GameId && rating.UserId == userId); if (existingRatingByUser != null) { existingRatingByUser.Rating = newRating.Rating; } else { GameRating gameRating = new GameRating { Id = Guid.NewGuid().ToString(), UserId = userId, Rating = newRating.Rating, GameId = newRating.GameId }; db.GameRatings.Add(gameRating); } db.SaveChanges(); // Get new average var ratings = db.GameRatings.Where(rating => rating.GameId == newRating.GameId); decimal averageRating = Convert.ToDecimal(ratings.Average(r => r.Rating)); var game = db.Games.FirstOrDefault(g => g.Id == newRating.GameId); if (game != null) { game.Rating = averageRating; db.SaveChanges(); } return(Json(new { Success = true, Rating = averageRating }, JsonRequestBehavior.AllowGet)); }
public JsonResult EditReview(GameReview review) { CVGSAppEntities db = new CVGSAppEntities(); try { var memberId = User.Identity.GetUserId(); var savedReview = db.GameReviews.FirstOrDefault(r => r.Id == review.Id); savedReview.ReviewText = review.ReviewText; savedReview.EditedOn = DateTime.Now; savedReview.Approved = false; db.SaveChanges(); return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { Success = false, Error = "Error occurred while editing review" }, JsonRequestBehavior.AllowGet)); } }
public JsonResult AddReview(GameReview review) { review.Id = Guid.NewGuid().ToString(); review.CreatedBy = User.Identity.GetUserId(); review.CreatedOn = DateTime.Now; review.EditedOn = DateTime.Now; review.Approved = false; CVGSAppEntities db = new CVGSAppEntities(); try { db.GameReviews.Add(review); db.SaveChanges(); return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { Success = false, Error = "Error occurred while adding review" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Library() { CVGSAppEntities db = new CVGSAppEntities(); var userId = User.Identity.GetUserId(); var categories = db.GameCategories.ToDictionary(item => item.Id, item => item.Name); var platforms = db.GamePlatforms.ToDictionary(item => item.Id, item => item.Name); var purchasedGames = GetPurchaseDGames(db, userId); foreach (var game in purchasedGames) { if (categories.Any()) { game.CategoryName = game.CategoryId == null ? "None" : categories[(int)game.CategoryId]; } if (platforms.Any()) { game.PlatformName = game.PlatformId == null ? "None" : platforms[(int)game.PlatformId]; } } return(View(purchasedGames)); }
// GET: Events public ActionResult Index() { CVGSAppEntities db = new CVGSAppEntities(); string userId = User.Identity.GetUserId(); List <EventDetailsViewModel> model = new List <EventDetailsViewModel> { }; IQueryable <Event> events = db.Events.Where(item => item.EndTime > DateTime.Now); foreach (Event @event in events) { EventDetailsViewModel modelObject = new EventDetailsViewModel { Event = @event, EventType = @event.IsIRL ? "In Person" : "Online", UserRegistered = db.EventAttendees.Any(u => u.EventId == @event.Id && u.AttendeeId == userId) }; model.Add(modelObject); } return(View(model)); }