public DestinationDetailViewModel(Destination theDestination, DestinationCategory category, Trail trail) { Id = theDestination.Id; Name = theDestination.Name; Street = theDestination.Street; City = theDestination.City; State = theDestination.State; Zipcode = theDestination.Zipcode; Description = theDestination.Description; OutdoorSeating = theDestination.OutdoorSeating; BikeRacks = theDestination.BikeRacks; Restrooms = theDestination.Restrooms; Playground = theDestination.Playground; CategoryId = theDestination.CategoryId; CategoryName = category.Name; TrailId = theDestination.TrailId; TrailName = trail.Name; Image = theDestination.Image; if (theDestination.Website != null && theDestination.Website != "") { if (!theDestination.Website.StartsWith("http")) { Website = "https://" + theDestination.Website; } else { Website = theDestination.Website; } } else { Website = null; } }
public IActionResult Detail(int id) { Destination destination = context.Destinations .Single(t => t.Id == id); DestinationCategory categories = context.DestinationCategories .Single(d => d.Id == destination.CategoryId); Trail trail = context.Trails .Single(t => t.Id == destination.TrailId); DestinationDetailViewModel theDestination = new DestinationDetailViewModel(destination, categories, trail); return(View(theDestination)); }
public DeleteDestinationViewModel(Destination theDestination, DestinationCategory category, Trail trail) { Id = theDestination.Id; Name = theDestination.Name; Street = theDestination.Street; City = theDestination.City; State = theDestination.State; Zipcode = theDestination.Zipcode; Description = theDestination.Description; Website = theDestination.Website; OutdoorSeating = theDestination.OutdoorSeating; BikeRacks = theDestination.BikeRacks; Restrooms = theDestination.Restrooms; Playground = theDestination.Playground; CategoryId = theDestination.CategoryId; CategoryName = category.Name; TrailId = theDestination.TrailId; TrailName = trail.Name; Image = theDestination.Image; }
/// <summary> /// Returns a random destination specified by its type( Position, SpawnPoint etc ) /// <param name="d"></param> /// <returns></returns> public Point GetRandomDestination(DestinationCategory d) { List <Point> subDestinations = new List <Point>(); foreach (var item in destinations) { if (item.type == d && !item.isOccupied) { subDestinations.Add(item); } } // meaning no destination available if (subDestinations.Count == 0) { return(null); } return(subDestinations[UnityEngine.Random.Range(0, subDestinations.Count)]); }
public IActionResult NeedingAdminApproval(int id) { UserDestination destinationSelected = context.UserDestinations .Include(d => d.Trail) .Include(d => d.Category) .Single(d => d.Id == id); DestinationCategory category = context.DestinationCategories.Find(destinationSelected.CategoryId); Trail trail = context.Trails.Find(destinationSelected.TrailId); Destination newDestination = new Destination { Name = destinationSelected.Name, Street = destinationSelected.Street, City = destinationSelected.City, State = destinationSelected.State, Zipcode = destinationSelected.Zipcode, Description = destinationSelected.Description, Website = destinationSelected.Website, OutdoorSeating = destinationSelected.OutdoorSeating, BikeRacks = destinationSelected.BikeRacks, Restrooms = destinationSelected.Restrooms, Playground = destinationSelected.Playground, Category = category, Trail = trail, CategoryId = destinationSelected.CategoryId, TrailId = destinationSelected.TrailId, Image = destinationSelected.Image, UserId = destinationSelected.UserId }; context.Destinations.Add(newDestination); context.UserDestinations.Remove(destinationSelected); context.SaveChanges(); return(Redirect("/Destination")); }
public IActionResult Add(AddDestinationViewModel viewModel) { string uniqueFileName = UploadedFile(viewModel); if (ModelState.IsValid && User.IsInRole("Admin")) { var userId = _userManager.GetUserId(User); DestinationCategory category = context.DestinationCategories.Find(viewModel.CategoryId); Trail trail = context.Trails.Find(viewModel.TrailId); if (!viewModel.Website.StartsWith("http")) { viewModel.Website = "https://" + viewModel.Website; } Destination newDestination = new Destination { Name = viewModel.Name, Street = viewModel.Street, City = viewModel.City, State = viewModel.State, Zipcode = viewModel.Zipcode, Description = viewModel.Description, Website = viewModel.Website, OutdoorSeating = viewModel.OutdoorSeating, BikeRacks = viewModel.BikeRacks, Restrooms = viewModel.Restrooms, Playground = viewModel.Playground, Category = category, Trail = trail, CategoryId = viewModel.CategoryId, TrailId = viewModel.TrailId, Image = uniqueFileName, UserId = userId }; context.Destinations.Add(newDestination); context.SaveChanges(); int id = newDestination.Id; return(Redirect("/destination/detail/" + id)); } else if (ModelState.IsValid && User.Identity.IsAuthenticated) { var userId = _userManager.GetUserId(User); DestinationCategory category = context.DestinationCategories.Find(viewModel.CategoryId); Trail trail = context.Trails.Find(viewModel.TrailId); if (!viewModel.Website.StartsWith("http")) { viewModel.Website = "https://" + viewModel.Website; } UserDestination newUserDestination = new UserDestination { Name = viewModel.Name, Street = viewModel.Street, City = viewModel.City, State = viewModel.State, Zipcode = viewModel.Zipcode, Description = viewModel.Description, Website = viewModel.Website, OutdoorSeating = viewModel.OutdoorSeating, BikeRacks = viewModel.BikeRacks, Restrooms = viewModel.Restrooms, Playground = viewModel.Playground, Category = category, Trail = trail, CategoryId = viewModel.CategoryId, TrailId = viewModel.TrailId, Image = uniqueFileName, UserId = userId }; context.UserDestinations.Add(newUserDestination); context.SaveChanges(); return(Redirect("/Destination/UserDestinations/")); } //repopulate SelectListItems List <DestinationCategory> categories = context.DestinationCategories.ToList(); List <Trail> trails = context.Trails.ToList(); List <SelectListItem> categoryList = new List <SelectListItem>(); foreach (var c in categories) { categoryList.Add(new SelectListItem { Value = c.Id.ToString(), Text = c.Name }); } List <SelectListItem> trailList = new List <SelectListItem>(); foreach (var t in trails) { trailList.Add(new SelectListItem { Value = t.Id.ToString(), Text = t.Name }); } viewModel.Category = categoryList; viewModel.Trail = trailList; return(View(viewModel)); }