Example #1
0
        public ActionResult Edit(int id, FullArmyData Army)
        {// we check if the form returned is validated
            if (!ModelState.IsValid)
            {
                return(View(Army));
            }
            ArmyBLL ArmyData = new ArmyBLL(Army);

            try
            {
                using (ContextBLL ctx = new ContextBLL())
                {
                    ctx.ArmyUpdate(ArmyData);
                    ctx.ArmyModelsDeleteByArmyID(Army.ArmyID);
                    for (int i = 0; i < Army.models.Count; i++)
                    {                    // to make sure we have a good save of the edited army data we delete the army data,
                        //then we put in the new army roster. I figured this is less taxing then pulling
                        //up the old roster, compare info, then delete, edit and create records accordingly.
                        ArmyModelBLL model = new ArmyModelBLL();
                        model.Quantity   = Army.models[i].Quantity;
                        model.FullSquats = Army.models[i].FullSquats;
                        model.ModelID    = Army.models[i].ModelID;
                        model.ArmyID     = Army.ArmyID;
                        //models.Add(model);
                        if (model.Quantity > 0)
                        {                        // if this model is in the army create a record in the many to many table.
                            ctx.ArmyModelCreate(model);
                        }
                    }
                }
                TempData.Add("Message", "Saved");                       //we use this message for a pop-up confirmation
                return(RedirectToAction("Edit", new { id = Army.ArmyID }));
                // sending to edit because I want the user to see the new values and do possible tweaks
                //till they are happy. saving just updates the info and calculates points.
            }
            catch (Exception oops)
            {
                Error.Log(oops);
                return(View("error", oops));
            }
        }
Example #2
0
 public ActionResult Edit(int id, ArmyBLL ArmyToEdit)
 {
     if (!ModelState.IsValid)
     {
         return(View(ArmyToEdit));
     }
     try
     {
         using (ContextBLL ctx = new ContextBLL())
         {
             ArmyToEdit.ArmyID = id;
             ctx.ArmyUpdate(ArmyToEdit);
         }
         return(RedirectToAction("Details", new { id = ArmyToEdit.ArmyID }));
     }
     catch (Exception oops)
     {
         Error.Log(oops);
         return(View("Error", oops));
     }
 }