public ActionResult Update(MunitionsPO form) { //Redirection to Index page for Munitions ActionResult oResponse = RedirectToAction("Index", "Munitions", new { form.TopicID }); //Checking for valid modelstate if (ModelState.IsValid) { try { //Mapping form objects from PO to DO MunitionsDO dataObject = MunitionsMapper.MapPOtoDO(form); //Passing objects to UpdateMunitions() dataAccess.UpdateMunitions(dataObject); TempData["Message"] = $"Successfully updated {form.Munition}"; } catch (Exception ex) { //Error message oResponse = View(form); TempData["ErrorMessage"] = "Update was unsuccessful"; } } //ModelState not valid else { //User filled form out incorrectly oResponse = View(form); } //Return redirect ActionResult return(oResponse); }
public ActionResult RenderTopics() { //Getting list of topics from data layer List <TopicDO> topics = dataAccess.ViewTopics(); List <TopicPO> mappedTopics = MunitionsMapper.MapDOtoPO(topics); //Returning list of topics for DDL return(PartialView("_TopicsButton", topics)); }
public ActionResult Index(Int64 topicID, string topic) { //Intantiating new list to return mappedMunitions List <MunitionsPO> mappedMunitions = new List <MunitionsPO>(); try { //Filling list of objects using method in data layer List <MunitionsDO> munitions = dataAccess.ViewMunitions(topicID); //Mapping to a list of presentation objects mappedMunitions = MunitionsMapper.MapDOtoPO(munitions); //Pass topicID even if there aren't munitions in table if (munitions.Count == 0) { mappedMunitions.Add(new MunitionsPO() { TopicID = topicID }); } //Using CoundVideos() to get a count of each munitionID List <MunitionBO> videoCount = businessAccess.CountVideos(dataAccess.MunitionCount()); //Putting list into viewbag as a list to display ViewBag.Videos = new List <MunitionBO>(); foreach (MunitionBO munition in videoCount) { ViewBag.Videos.Add(new MunitionBO() { MunitionID = munition.MunitionID, VideoCount = munition.VideoCount }); } //Creating viewbag for topic ViewBag.Topic = topic; } catch (Exception ex) { //Error message TempData["ErrorMessage"] = "There was an issue displaying Munitions"; } //Returning list of munitions to be displayed in Index view return(View(mappedMunitions)); }
public ActionResult Update(Int64 topicID, Int64 munitionID) { //Viewing munition with specific munitionID selected ActionResult oResponse = View(munitionID); try { //Getting munition by ID from data layer and mapping to presentation layer MunitionsDO munitions = dataAccess.ViewMunitionsByID(munitionID); MunitionsPO displayObject = MunitionsMapper.MapDOtoPO(munitions); //Setting topic ID to current topic displayObject.TopicID = topicID; oResponse = View(displayObject); } catch (Exception ex) { //Error message TempData["Message"] = "Munition could not be updated at this time."; } //Return ActionResult return(oResponse); }