Exemple #1
0
        // GET: ArmyModels/Edit
        public ActionResult Edit(int id)
        {           // this will show the army info, but will also show a list of models that come with the army
            List <ArmyModelBLL> models = null;
            ArmyBLL             army   = null;

            try
            {
                using (ContextBLL ctx = new ContextBLL())
                {
                    army = ctx.ArmyFindByID(id);
                    if (army == null)
                    {
                        return(View("NotFound"));
                    }
                    models = ctx.ArmyModelsFindByFactionID(army.ArmyID, army.FactionID, Constants.DefaultPageNumber, Constants.DefaultPageSize);

                    #region Pulldown Stuff
                    //We want to make pull down menus for models so we can easily select the quantity and
                    //amount of full squats we can select. These menus are restricted by the field allowence.
                    List <List <SelectListItem> > FieldAllowance = new List <List <SelectListItem> >();
                    List <List <SelectListItem> > FullSquats     = new List <List <SelectListItem> >();
                    ViewBag.MaxFieldAllowance = FieldAllowance;
                    ViewBag.MaxFullSquats     = FullSquats;

                    for (int i = 0; i < models.Count; i++)
                    {
                        FieldAllowance.Add(new List <SelectListItem>());
                        FullSquats.Add(new List <SelectListItem>());
                        int MaxQuantity = 0;
                        if (0 != models[i].AttachesToModelID)
                        {                        // limits the attached models to qty of parent model
                            ArmyModelBLL OriginalModel = ctx.ArmyModelsFindByArmyIDAndModelID(army.ArmyID, models[i].AttachesToModelID);
                            MaxQuantity = OriginalModel.Quantity;
                        }
                        else
                        {
                            MaxQuantity = models[i].FieldAllowence;
                        }
                        for (int j = 0; j < MaxQuantity + 1; j++)
                        {        //this is the list for the quantity
                            SelectListItem sli = new SelectListItem();
                            sli.Text  = j.ToString();
                            sli.Value = j.ToString();
                            if (j == models[i].Quantity)
                            {
                                sli.Selected = true;
                            }
                            FieldAllowance[i].Add(sli);
                        }
                        for (int jj = 0; jj < models[i].Quantity + 1; jj++)
                        {           // this is the list for the Full squats. we limit this to the quantity ,
                            // since full squat is an upgrade to a squat
                            // it makes no sense to make a selection larger then the amount of squats.
                            SelectListItem sli = new SelectListItem();
                            sli.Text  = jj.ToString();
                            sli.Value = jj.ToString();
                            if (jj == models[i].FullSquats)
                            {
                                sli.Selected = true;
                            }
                            FullSquats[i].Add(sli);
                        }
                    }
                    #endregion Pulldown stuff
                }
            }
            catch (Exception oops)
            {            //error logger and divert to error screen
                Error.Log(oops);
                return(View("error", oops));
            }
            FullArmyData item = new FullArmyData(army, models);
            item.models = models;
            if (!IsMineOrAdmin(item))
            {            // check if user should be editing this
                return(View("Porpoise"));
            }
            return(View(item));
        }