public async Task <IActionResult> Copy(int?id) { if (id == null) { return(NotFound()); } SelectList week = new SelectList(_context.Week, "WeekId", "WeekNumber"); ViewBag.week = week; var battalion = await _context.Battalions .FirstOrDefaultAsync(m => m.BattalionId == id); CombatFormationViewModel combatForm = new CombatFormationViewModel() { Name = battalion.Name, Number = battalion.Number, TotalStrenght = battalion.TotalStrenght, AdditionalInformation = battalion.AdditionalInformation, Commanders = battalion.Commanders, RegimentId = battalion.RegimentId, WeekId = battalion.WeekId, Image = battalion.Image, Week = battalion.Week, OldWeekId = battalion.WeekId, Coordinates = battalion.CoordinatesXY, CoordX = battalion.CoordX, CoordY = battalion.CoordY, Adress = battalion.Adress }; return(View(combatForm)); }
public async Task <IActionResult> Copy(int?id) { if (id == null) { return(NotFound()); } SelectList week = new SelectList(_context.Week, "WeekId", "WeekNumber"); ViewBag.week = week; var army = await _context.Armies .FirstOrDefaultAsync(m => m.ArmyId == id); CombatFormationViewModel combatForm = new CombatFormationViewModel() { Name = army.Name, TotalStrenght = army.TotalStrenght, AdditionalInformation = army.AdditionalInformation, Number = army.Number, Commanders = army.Commanders, Corps = army.Corps, Divisions = army.Divisions, Brigades = army.Brigades, BattleFrontId = army.BattleFrontId, OldWeekId = army.WeekId, WeekId = army.WeekId, Image = army.Image, Coordinates = army.CoordinatesXY, CoordX = army.CoordX, CoordY = army.CoordY, Adress = army.Adress }; return(View(combatForm)); }
public async Task <IActionResult> Copy(int?id) { if (id == null) { return(NotFound()); } SelectList week = new SelectList(_context.Week, "WeekId", "WeekNumber"); ViewBag.week = week; var battleFront = await _context.BattleFronts .FirstOrDefaultAsync(m => m.BattleFrontId == id); CombatFormationViewModel combatForm = new CombatFormationViewModel() { Name = battleFront.Name, TotalStrenght = battleFront.TotalStrenght, Commanders = battleFront.Commanders, Armies = battleFront.Armies, WeekId = battleFront.WeekId, Image = battleFront.Image, Coordinates = battleFront.CoordinatesXY, CoordX = battleFront.CoordX, CoordY = battleFront.CoordY, Adress = battleFront.Adress }; return(View(combatForm)); }
public async Task <IActionResult> Create(CombatFormationViewModel combatForm) { Army army = new Army() { Name = combatForm.Name, TotalStrenght = combatForm.TotalStrenght, Number = combatForm.Number, Commanders = combatForm.Commanders, Corps = combatForm.Corps, Divisions = combatForm.Divisions, Brigades = combatForm.Brigades, BattleFrontId = combatForm.BattleFrontId, WeekId = combatForm.WeekId, Image = combatForm.Image, AdditionalInformation = combatForm.AdditionalInformation, CoordinatesXY = combatForm.Coordinates, Adress = combatForm.Adress }; if (ModelState.IsValid) { if (combatForm.Coordinates != null) { string[] str = combatForm.Coordinates.Split(',', 2, StringSplitOptions.None); army.CoordX = str[0]; army.CoordY = str[1]; } if (combatForm.File != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(combatForm.File.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)combatForm.File.Length); } // установка массива байтов army.Image = imageData; } _context.Add(army); await _context.SaveChangesAsync(); return(RedirectToAction("Edit", new { id = army.ArmyId })); //return RedirectToAction(nameof(Index)); } return(View(army)); }
public async Task <IActionResult> Create(CombatFormationViewModel combatForm) { Brigade brigade = new Brigade() { Name = combatForm.Name, Number = combatForm.Number, TotalStrenght = combatForm.TotalStrenght, AdditionalInformation = combatForm.AdditionalInformation, Commanders = combatForm.Commanders, Regiments = combatForm.Regiments, WeekId = combatForm.WeekId, DivisionId = combatForm.DivisionId, ArmyId = combatForm.ArmyId, CorpsId = combatForm.CorpsId, Image = combatForm.Image, Week = combatForm.Week, CoordinatesXY = combatForm.Coordinates, CoordX = combatForm.CoordX, CoordY = combatForm.CoordY, Adress = combatForm.Adress }; if (ModelState.IsValid) { if (combatForm.Coordinates != null) { string[] str = combatForm.Coordinates.Split(',', 2, StringSplitOptions.None); brigade.CoordX = str[0]; brigade.CoordY = str[1]; } if (combatForm.File != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(combatForm.File.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)combatForm.File.Length); } // установка массива байтов brigade.Image = imageData; } _context.Add(brigade); await _context.SaveChangesAsync(); return(RedirectToAction("Edit", new { id = brigade.BrigadeId })); } return(View(brigade)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var corps = await _context.Corpss.FindAsync(id); SelectList week = new SelectList(_context.Week, "WeekId", "WeekNumber"); ViewBag.week = week; SelectList armies = new SelectList(_context.Armies.Where(f => f.WeekId == corps.WeekId), "ArmyId", "Name"); ViewBag.Armies = armies; if (corps == null) { return(NotFound()); } CombatFormationViewModel combatForm = new CombatFormationViewModel() { Id = corps.CorpsId, Name = corps.Name, Number = corps.Number, TotalStrenght = corps.TotalStrenght, AdditionalInformation = corps.AdditionalInformation, Commanders = corps.Commanders, Divisions = corps.Divisions, Brigades = corps.Brigades, Regiments = corps.Regiments, Battalions = corps.Battalions, BattleFrontId = corps.BattlefrontId, OldWeekId = corps.WeekId, WeekId = corps.WeekId, Image = corps.Image, Week = corps.Week, Coordinates = corps.CoordinatesXY, CoordX = corps.CoordX, CoordY = corps.CoordY, Adress = corps.Adress }; return(View(combatForm)); }
public async Task <IActionResult> Create(CombatFormationViewModel combatForm) { BattleFront battleFront = new BattleFront() { //BattleFrontId = combatForm.Id, Name = combatForm.Name, TotalStrenght = combatForm.TotalStrenght, Commanders = combatForm.Commanders, Armies = combatForm.Armies, WeekId = combatForm.WeekId, Image = combatForm.Image, CoordinatesXY = combatForm.Coordinates, CoordX = combatForm.CoordX, CoordY = combatForm.CoordY, Adress = combatForm.Adress }; if (ModelState.IsValid) { if (combatForm.Coordinates != null) { string[] str = combatForm.Coordinates.Split(',', 2, StringSplitOptions.None); battleFront.CoordX = str[0]; battleFront.CoordY = str[1]; } if (combatForm.File != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(combatForm.File.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)combatForm.File.Length); } // установка массива байтов battleFront.Image = imageData; } _context.Add(battleFront); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(battleFront)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var division = await _context.Divisions.FindAsync(id); SelectList week = new SelectList(_context.Week, "WeekId", "WeekNumber"); ViewBag.week = week; SelectList corpuslist = new SelectList(_context.Corpss.Where(f => f.WeekId == division.WeekId), "CorpsId", "Name"); ViewBag.corpusList = corpuslist; if (division == null) { return(NotFound()); } CombatFormationViewModel combatForm = new CombatFormationViewModel() { Id = division.DivisionId, Name = division.Name, Number = division.Number, TotalStrenght = division.TotalStrenght, AdditionalInformation = division.AdditionalInformation, Commanders = division.Commanders, Brigades = division.Brigades, Regiments = division.Regiments, ArmyId = division.ArmyId, CorpsId = division.CorpsId, WeekId = division.WeekId, OldWeekId = division.WeekId, Image = division.Image, Week = division.Week, Coordinates = division.CoordinatesXY, CoordX = division.CoordX, CoordY = division.CoordY, Adress = division.Adress }; return(View(combatForm)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var army = await _context.Armies.FindAsync(id); if (army == null) { return(NotFound()); } CombatFormationViewModel combatForm = new CombatFormationViewModel() { Name = army.Name, TotalStrenght = army.TotalStrenght, Number = army.Number, Commanders = army.Commanders, Corps = army.Corps, Divisions = army.Divisions, Brigades = army.Brigades, BattleFrontId = army.BattleFrontId, OldWeekId = army.WeekId, WeekId = army.WeekId, Image = army.Image, AdditionalInformation = army.AdditionalInformation, Coordinates = army.CoordinatesXY, Adress = army.Adress, CoordX = army.CoordX, CoordY = army.CoordY }; SelectList week = new SelectList(_context.Week, "WeekId", "WeekNumber"); ViewBag.week = week; ViewBag.OldWeek = army.WeekId; SelectList fronts = new SelectList(_context.BattleFronts.Where(f => f.WeekId == army.WeekId), "BattleFrontId", "Name"); ViewBag.Fronts = fronts; return(View(combatForm)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var brigade = await _context.Brigades.FindAsync(id); SelectList week = new SelectList(_context.Week, "WeekId", "WeekNumber"); ViewBag.week = week; SelectList divList = new SelectList(_context.Divisions.Where(f => f.WeekId == brigade.WeekId), "DivisionId", "Name"); ViewBag.divList = divList; CombatFormationViewModel combatForm = new CombatFormationViewModel() { Id = brigade.BrigadeId, Name = brigade.Name, Number = brigade.Number, TotalStrenght = brigade.TotalStrenght, AdditionalInformation = brigade.AdditionalInformation, Commanders = brigade.Commanders, Battalions = brigade.Battalions, Regiments = brigade.Regiments, DivisionId = brigade.DivisionId, ArmyId = brigade.ArmyId, CorpsId = brigade.CorpsId, WeekId = brigade.WeekId, OldWeekId = brigade.WeekId, Image = brigade.Image, Week = brigade.Week, Coordinates = brigade.CoordinatesXY, CoordX = brigade.CoordX, CoordY = brigade.CoordY, Adress = brigade.Adress }; return(View(combatForm)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var regiment = await _context.Regiments.FindAsync(id); SelectList week = new SelectList(_context.Week, "WeekId", "WeekNumber"); ViewBag.week = week; SelectList brigList = new SelectList(_context.Brigades.Where(f => f.WeekId == regiment.WeekId), "BrigadeId", "Name"); ViewBag.brigList = brigList; if (regiment == null) { return(NotFound()); } CombatFormationViewModel combatForm = new CombatFormationViewModel() { Id = regiment.RegimentId, Name = regiment.Name, Number = regiment.Number, TotalStrenght = regiment.TotalStrenght, AdditionalInformation = regiment.AdditionalInformation, Commanders = regiment.Commanders, BrigadeId = regiment.BrigadeId, WeekId = regiment.WeekId, Image = regiment.Image, Week = regiment.Week, OldWeekId = regiment.WeekId, Coordinates = regiment.CoordinatesXY, CoordX = regiment.CoordX, CoordY = regiment.CoordY, Adress = regiment.Adress }; return(View(combatForm)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var battalion = await _context.Battalions.FindAsync(id); SelectList regList = new SelectList(_context.Regiments.Where(f => f.WeekId == battalion.WeekId), "RegimentId", "Name"); ViewBag.regList = regList; SelectList week = new SelectList(_context.Week, "WeekId", "WeekNumber"); ViewBag.week = week; if (battalion == null) { return(NotFound()); } CombatFormationViewModel combatForm = new CombatFormationViewModel() { Id = battalion.BattalionId, Name = battalion.Name, Number = battalion.Number, TotalStrenght = battalion.TotalStrenght, AdditionalInformation = battalion.AdditionalInformation, Commanders = battalion.Commanders, RegimentId = battalion.RegimentId, WeekId = battalion.WeekId, OldWeekId = battalion.WeekId, Image = battalion.Image, Week = battalion.Week, Coordinates = battalion.CoordinatesXY, CoordX = battalion.CoordX, CoordY = battalion.CoordY, Adress = battalion.Adress }; return(View(combatForm)); }
public async Task <IActionResult> Copy(int?id) { if (id == null) { return(NotFound()); } SelectList week = new SelectList(_context.Week, "WeekId", "WeekNumber"); ViewBag.week = week; var corps = await _context.Corpss .FirstOrDefaultAsync(m => m.CorpsId == id); CombatFormationViewModel combatForm = new CombatFormationViewModel() { Name = corps.Name, Number = corps.Number, TotalStrenght = corps.TotalStrenght, AdditionalInformation = corps.AdditionalInformation, Commanders = corps.Commanders, Divisions = corps.Divisions, Brigades = corps.Brigades, Regiments = corps.Regiments, Battalions = corps.Battalions, BattleFrontId = corps.BattlefrontId, OldWeekId = corps.WeekId, WeekId = corps.WeekId, Image = corps.Image, Week = corps.Week, Coordinates = corps.CoordinatesXY, CoordX = corps.CoordX, CoordY = corps.CoordY, Adress = corps.Adress }; return(View(combatForm)); }
public async Task <IActionResult> Copy(int id, CombatFormationViewModel combatForm) { Battalion battalion = new Battalion() { Name = combatForm.Name, Number = combatForm.Number, TotalStrenght = combatForm.TotalStrenght, AdditionalInformation = combatForm.AdditionalInformation, Commanders = combatForm.Commanders, WeekId = combatForm.WeekId, RegimentId = combatForm.RegimentId, Image = combatForm.Image, Week = combatForm.Week, CoordinatesXY = combatForm.Coordinates, CoordX = combatForm.CoordX, CoordY = combatForm.CoordY, Adress = combatForm.Adress }; if (ModelState.IsValid) { if (combatForm.OldWeekId != battalion.WeekId) { battalion.RegimentId = null; battalion.Commanders = null; } if (combatForm.Coordinates != null) { string[] str = combatForm.Coordinates.Split(',', 2, StringSplitOptions.None); battalion.CoordX = str[0]; battalion.CoordY = str[1]; } if (combatForm.File != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(combatForm.File.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)combatForm.File.Length); } // установка массива байтов battalion.Image = imageData; try { _context.Add(battalion); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateConcurrencyException) { if (!BattalionExists(battalion.BattalionId)) { return(NotFound()); } else { throw; } } } else if (combatForm.File == null) { battalion.Image = combatForm.Image; try { _context.Add(battalion); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BattalionExists(battalion.BattalionId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } } return(View(battalion)); }
public async Task <IActionResult> Edit(int id, CombatFormationViewModel combatForm) { if (id != combatForm.Id) { return(NotFound()); } Army army = new Army() { ArmyId = combatForm.Id, Name = combatForm.Name, TotalStrenght = combatForm.TotalStrenght, Number = combatForm.Number, Commanders = combatForm.Commanders, Corps = combatForm.Corps, Divisions = combatForm.Divisions, Brigades = combatForm.Brigades, BattleFrontId = combatForm.BattleFrontId, AdditionalInformation = combatForm.AdditionalInformation, WeekId = combatForm.WeekId, Image = combatForm.Image, CoordinatesXY = combatForm.Coordinates, Adress = combatForm.Adress, CoordX = combatForm.CoordX, CoordY = combatForm.CoordY }; if (ModelState.IsValid) { if (combatForm.OldWeekId != army.WeekId) { army.Commanders = null; army.Corps = null; army.Divisions = null; army.Brigades = null; army.BattleFrontId = null; } if (combatForm.Coordinates != null) { string[] str = combatForm.Coordinates.Split(',', 2, StringSplitOptions.None); army.CoordX = str[0]; army.CoordY = str[1]; } if (combatForm.File != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(combatForm.File.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)combatForm.File.Length); } // установка массива байтов army.Image = imageData; try { _context.Update(army); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (DbUpdateConcurrencyException) { if (!ArmyExists(army.ArmyId)) { return(NotFound()); } else { throw; } } } else if (combatForm.File == null) { army.Image = combatForm.Image; try { _context.Update(army); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ArmyExists(army.ArmyId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } } return(View(army)); }