public ActionResult AdvancedSearch() { ViewBag.AvailableTags = db.MissionTagTypes.Select(t => t.TagName).ToList(); ViewBag.MinimumLevelSelectList = new SelectList(MissionHelper.GetMinimumLevelSelectList(true), "Value", "Text"); ViewBag.Factions = new SelectList(MissionHelper.GetFactionSelectList(true), "Value", "Text"); return(View()); }
public ActionResult Submit() { List <SelectListItem> publishedSelectItems = MissionHelper.GetYesNoSelectList(); ViewBag.AvailableTags = db.MissionTagTypes.Select(t => t.TagName).ToList(); ViewBag.PublishedSelectList = new SelectList(publishedSelectItems, "Value", "Text"); ViewBag.MinimumLevelSelectList = new SelectList(MissionHelper.GetMinimumLevelSelectList(), "Value", "Text"); return(View()); }
private ActionResult Edit(EditMissionViewModel missionViewModel) { if (ModelState.IsValid) { //check if cryptic id is already used if (db.Missions.Any(m => m.CrypticId.Equals(missionViewModel.CrypticId) && m.Id != missionViewModel.Id)) { ModelState.AddModelError("DuplicateCrypticID", "Cryptic ID already exists."); List <SelectListItem> publishedSelectItems = MissionHelper.GetYesNoSelectList(); ViewBag.AvailableTags = db.MissionTagTypes.Select(t => t.TagName).ToList(); ViewBag.PublishedSelectList = new SelectList(publishedSelectItems, "Value", "Text"); ViewBag.MinimumLevelSelectList = new SelectList(MissionHelper.GetMinimumLevelSelectList(), "Value", "Text"); return(View("edit", missionViewModel)); } var mission = db.Missions.Find(missionViewModel.Id); var user = mission.Author; mission.CrypticId = missionViewModel.CrypticId.ToUpper(); mission.Name = missionViewModel.Name; mission.Description = missionViewModel.Description; mission.Length = missionViewModel.Length; mission.Faction = missionViewModel.Faction; mission.MinimumLevel = missionViewModel.MinimumLevel; mission.Spotlit = missionViewModel.Spotlit; mission.Status = missionViewModel.Status; mission.DateLastUpdated = DateTime.Now; // in case the tags list is null create a blank one if (missionViewModel.Tags == null) { missionViewModel.Tags = new List <string>(); } //first remove the tags that don't exist anymore var currentTags = mission.Tags.ToList(); foreach (var tag in currentTags) { if (!missionViewModel.Tags.Contains(tag.TagName)) { mission.Tags.Remove(tag); } } //now add the tags that don't exist foreach (var tag in missionViewModel.Tags) { var tagType = db.MissionTagTypes.FirstOrDefault(t => t.TagName.Equals(tag)); if (tagType != null) { if (!mission.Tags.Contains(tagType)) { mission.Tags.Add(tagType); } } } db.SaveChanges(); //now do images try { var changedImages = false; //set some defaults in case its null #region Defaults if (missionViewModel.OldImages == null) { missionViewModel.OldImages = new List <string>(); } if (missionViewModel.Images == null) { missionViewModel.Images = new List <HttpPostedFileBase>(); } if (mission.Images == null) { mission.Images = new List <MissionImage>(); } #endregion //check for removed images first //if its different then a change was made, need to remove the images if (missionViewModel.OldImages.Count != mission.Images.Count) { MissionImagesHelper.CheckForRemovedImages(db, mission, missionViewModel.OldImages); changedImages = true; } //add new images if (missionViewModel.Images.Count > 0) { var images = MissionImagesHelper.ValidateImages(missionViewModel.Images); MissionImagesHelper.AddImages(images, mission); changedImages = true; } if (changedImages) { db.SaveChanges(); } } catch { TempData["Message"] = "An error occured while editing images."; } //now do videos try { var changedVideos = false; //set some defaults in case its null #region Defaults if (missionViewModel.OldVideos == null) { missionViewModel.OldVideos = new List <string>(); } if (missionViewModel.Videos == null) { missionViewModel.Videos = new List <string>(); } if (mission.Videos == null) { mission.Videos = new List <YoutubeVideo>(); } #endregion //check for removed videos first //if its different then a change was made, need to remove the videos if (missionViewModel.OldVideos.Count != mission.Videos.Count) { MissionVideosHelper.CheckForRemovedVideos(db, mission, missionViewModel.OldVideos); changedVideos = true; } //add new videos if (missionViewModel.Videos.Count > 0) { var videos = MissionVideosHelper.GetVideoIds(missionViewModel.Videos); MissionVideosHelper.AddVideos(videos, mission); changedVideos = true; } if (changedVideos) { db.SaveChanges(); } } catch { TempData["Message"] = "An error occured while editing images."; } return(RedirectToAction("details", new { link = mission.MissionLink })); } return(View("edit", missionViewModel)); }
public ActionResult Edit(string link) { if (string.IsNullOrEmpty(link)) { return(RedirectToAction("index", "home")); } Mission mission = db.Missions.Where(m => m.MissionLink.Equals(link)).FirstOrDefault(); if (mission == null) { return(HttpNotFound()); } //only people who can edit a mission are the author or an admin if (!mission.Author.UserName.Equals(User.Identity.Name) && !User.IsInRole(ConstantsHelper.AdminRole)) { return(HttpNotFound()); } //if the user is not an admin and it is removed it doesn't exist if (mission.Status == MissionStatus.Removed && !User.IsInRole(ConstantsHelper.AdminRole)) { return(HttpNotFound()); } var publishedSelectItems = new List <SelectListItem>(); #region Published Select List publishedSelectItems.Add(new SelectListItem() { Value = "false", Text = "No", }); publishedSelectItems.Add(new SelectListItem() { Value = "true", Text = "Yes", }); #endregion var editModel = new EditMissionViewModel(); editModel.Id = mission.Id; editModel.CrypticId = mission.CrypticId; editModel.Name = mission.Name; editModel.Description = mission.Description; editModel.Length = mission.Length; editModel.Faction = mission.Faction; editModel.MinimumLevel = mission.MinimumLevel; editModel.Spotlit = mission.Spotlit; editModel.Published = mission.Published; editModel.Status = mission.Status; editModel.Author = mission.Author; editModel.AutoApprove = mission.Author.AutoApproval; editModel.Tags = mission.Tags.Select(t => t.TagName).ToList(); editModel.OldImages = mission.Images.OrderBy(i => i.Order).Select(i => i.Filename).ToList(); editModel.OldVideos = mission.Videos.OrderBy(v => v.Order).Select(v => v.YoutubeVideoId).ToList(); mission.MissionLink = MissionHelper.GetMissionLink(db, mission); var unselectedTags = db.MissionTagTypes.Select(t => t.TagName).ToList(); foreach (var tags in editModel.Tags) { unselectedTags.Remove(tags); } ViewBag.AvailableTags = unselectedTags; ViewBag.PublishedSelectList = new SelectList(publishedSelectItems, "Value", "Text"); ViewBag.MinimumLevelSelectList = new SelectList(MissionHelper.GetMinimumLevelSelectList(), "Value", "Text"); return(View(editModel)); }
public ActionResult Submit([Bind(Include = "CrypticId,Name,Description,Length,Faction,MinimumLevel,Spotlit,Published,Tags,Images,Videos")] SubmitMissionViewModel missionViewModel, string submitButton) { if (ModelState.IsValid) { //check if cryptic id is already used if (db.Missions.Any(m => m.CrypticId.Equals(missionViewModel.CrypticId))) { ModelState.AddModelError("DuplicateCrypticID", "Cryptic ID already exists."); List <SelectListItem> publishedSelectItems = MissionHelper.GetYesNoSelectList(); ViewBag.AvailableTags = db.MissionTagTypes.Select(t => t.TagName).ToList(); ViewBag.PublishedSelectList = new SelectList(publishedSelectItems, "Value", "Text"); ViewBag.MinimumLevelSelectList = new SelectList(MissionHelper.GetMinimumLevelSelectList(), "Value", "Text"); return(View(missionViewModel)); } ApplicationUser user = db.Users.FirstOrDefault(u => u.UserName.Equals(User.Identity.Name)); Mission mission = new Mission(); #region Copy Info mission.CrypticId = missionViewModel.CrypticId.ToUpper(); mission.Description = missionViewModel.Description; mission.Faction = missionViewModel.Faction; mission.Length = missionViewModel.Length; mission.MinimumLevel = missionViewModel.MinimumLevel; mission.Name = missionViewModel.Name; mission.Published = missionViewModel.Published; mission.Spotlit = missionViewModel.Spotlit; #endregion if (missionViewModel.Tags != null && missionViewModel.Tags.Count > 0) { mission.Tags = db.MissionTagTypes.Where(t => missionViewModel.Tags.Contains(t.TagName)).ToList(); } else { mission.Tags = new List <MissionTagType>(); } mission.MissionLink = MissionHelper.GetMissionLink(db, mission); mission.Author = user; mission.DateAdded = DateTime.Now; mission.DateLastUpdated = DateTime.Now; if (submitButton.Equals("Save and Publish")) { if (user.AutoApproval) { mission.Status = Models.FoundryMissionModels.Enums.MissionStatus.Published; } else { mission.Status = Models.FoundryMissionModels.Enums.MissionStatus.InReview; //mission.Status = Models.FoundryMissionModels.Enums.MissionStatus.Published; try { EmailHelper.ReportMissionNeedsApproval(mission); } catch { } } } else //if (submitButton.Equals("Save")) { //don't do anything, leave it at the current status (default = unpublished) //mission.Status = Models.FoundryMissionModels.Enums.MissionStatus.Unpublished; } mission.Spotlit = false; db.Missions.Add(mission); db.SaveChanges(); //remove null if there is a null if (missionViewModel.Images.Count > 0) { if (missionViewModel.Images[missionViewModel.Images.Count - 1] == null) { missionViewModel.Images.RemoveAt(missionViewModel.Images.Count - 1); } } if (missionViewModel.Images.Count > 0) { try { var images = MissionImagesHelper.ValidateImages(missionViewModel.Images); MissionImagesHelper.AddImages(images, mission); db.SaveChanges(); } catch { TempData["Message"] = "An error occured while adding images."; } } //remove null if there is a null if (missionViewModel.Videos.Count > 0) { if (missionViewModel.Videos[missionViewModel.Videos.Count - 1] == null) { missionViewModel.Videos.RemoveAt(missionViewModel.Videos.Count - 1); } } if (missionViewModel.Videos.Count > 0) { try { var videos = MissionVideosHelper.GetVideoIds(missionViewModel.Videos); MissionVideosHelper.AddVideos(videos, mission); db.SaveChanges(); } catch { if (!string.IsNullOrEmpty(TempData[""] as string)) { TempData["Message"] = "Errors when adding images and videos."; } else { TempData["Message"] = "An error occured while adding videos."; } } } return(RedirectToAction("details", new { link = mission.MissionLink })); } return(View(missionViewModel)); }