예제 #1
0
        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);
        }
예제 #2
0
        public ActionResult Create(int topicID)
        {
            //Intantiating MunitionsPO to get topicID
            MunitionsPO munitions = new MunitionsPO();

            munitions.TopicID = topicID;

            //Returning view
            return(View(munitions));
        }
예제 #3
0
        //Mapping one Munition from DO to PO
        public static MunitionsPO MapDOtoPO(MunitionsDO from)
        {
            MunitionsPO to = new MunitionsPO();

            to.MunitionID  = from.MunitionID;
            to.Munition    = from.Munition;
            to.Description = from.Description;
            to.TopicID     = from.TopicID;

            //Returning Munition
            return(to);
        }
예제 #4
0
        //Mapping list of Munitions from DO to PO
        public static List <MunitionsPO> MapDOtoPO(List <MunitionsDO> from)
        {
            List <MunitionsPO> to = new List <MunitionsPO>();

            if (from != null)
            {
                foreach (MunitionsDO item in from)
                {
                    //Changing a DO munition to a PO munition
                    MunitionsPO mappedItem = MapDOtoPO(item);
                    //Adding PO munition to a list of PO munitions
                    to.Add(mappedItem);
                }
            }

            //Returning list of Munitions
            return(to);
        }
예제 #5
0
        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);
        }