public ArmyModelBLL FullTroop() { //sample full troop with info to test ArmyModelBLL ReturnValue = new ArmyModelBLL(); ReturnValue.Quantity = 1; ReturnValue.PointCost = 10; ReturnValue.FullCrewPointCost = 15; ReturnValue.FullSquats = 1; ReturnValue.ModelType = 2; return(ReturnValue); }
public ArmyModelBLL WarJack() { //sample warjack with info required to test ArmyModelBLL ReturnValue = new ArmyModelBLL(); ReturnValue.Quantity = 1; ReturnValue.PointCost = 10; ReturnValue.FullCrewPointCost = 0; ReturnValue.FullSquats = 0; ReturnValue.ModelType = 1; return(ReturnValue); }
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)); } }
// 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)); }