public async Task <IActionResult> Copy(int?id) { SelectList weeks = new SelectList(_context.Week, "WeekId", "WeekNumber"); ViewBag.weeks = weeks; if (id == null) { return(NotFound()); } var commander = await _context.Commander .FirstOrDefaultAsync(m => m.id == id); CommanderViewModel commanderVM = new CommanderViewModel() { Name = commander.Name, Surname = commander.Surname, Paronymic = commander.Paronymic, DateOfBirth = commander.DateOfBirth, Position = commander.Position, AdditionalInformation = commander.AdditionalInformation, //WeekId = commander.WeekId, Image = commander.Image }; //Array.Copy(commander.Image, commanderVM.Image, commander.Image.Length); return(View(commanderVM)); }
public async Task <IActionResult> Create(CommanderViewModel commanderVM) { Commander commander = new Commander() { Name = commanderVM.Name, Surname = commanderVM.Surname, Paronymic = commanderVM.Paronymic, DateOfBirth = commanderVM.DateOfBirth, Position = commanderVM.Position, AdditionalInformation = commanderVM.AdditionalInformation, WeekId = commanderVM.WeekId //Week = commanderVM.Week }; if (ModelState.IsValid) { if (commanderVM.File != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(commanderVM.File.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)commanderVM.File.Length); } // установка массива байтов commander.Image = imageData; } _context.Add(commander); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["WeekId"] = new SelectList(_context.Week, "WeekId", "WeekId", commander.WeekId); return(View(commander)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var commander = await _context.Commander.FindAsync(id); if (commander == null) { return(NotFound()); } CommanderViewModel commanderVM = new CommanderViewModel() { id = commander.id, Name = commander.Name, Surname = commander.Surname, Paronymic = commander.Paronymic, DateOfBirth = commander.DateOfBirth, Position = commander.Position, AdditionalInformation = commander.AdditionalInformation, WeekId = commander.WeekId, Image = commander.Image, BattleFrontId = commander.BattleFrontId, ArmyId = commander.ArmyId, CorpsId = commander.CorpsId, DivisionId = commander.DivisionId, BrigadeId = commander.BrigadeId, RegimentId = commander.RegimentId, BattalionId = commander.BattalionId }; ViewData["WeekId"] = new SelectList(_context.Week, "WeekId", "WeekId", commander.WeekId); SelectList fronts = new SelectList(_context.BattleFronts.Where(f => f.WeekId == commander.WeekId), "BattleFrontId", "Name"); ViewBag.Fronts = fronts; SelectList armies = new SelectList(_context.Armies.Where(f => f.WeekId == commander.WeekId), "ArmyId", "Name"); ViewBag.Armies = armies; SelectList corpuslist = new SelectList(_context.Corpss.Where(f => f.WeekId == commander.WeekId), "CorpsId", "Name"); ViewBag.corpusList = corpuslist; SelectList divList = new SelectList(_context.Divisions.Where(f => f.WeekId == commander.WeekId), "DivisionId", "Name"); ViewBag.divList = divList; SelectList brigList = new SelectList(_context.Brigades.Where(f => f.WeekId == commander.WeekId), "BrigadeId", "Name"); ViewBag.brigList = brigList; SelectList regList = new SelectList(_context.Regiments.Where(f => f.WeekId == commander.WeekId), "RegimentId", "Name"); ViewBag.regList = regList; SelectList battalionList = new SelectList(_context.Battalions.Where(f => f.WeekId == commander.WeekId), "BattalionId", "Name"); ViewBag.battalionList = battalionList; return(View(commanderVM)); }
public ActionResult Delete(int?Idcom) { CommanderViewModel od = new CommanderViewModel(); if (Idcom != null) { var objet_modifier = com.Commanders.Where(x => x.Idcom == Idcom).First(); od.Idcom = objet_modifier.Idcom; } return(View(od)); }
public CommanderWindow() { InitializeComponent(); Cvm = new CommanderViewModel(); this.DataContext = this; if (Config.Get().RequireCredentials) { var loginWindow = new LoginControl(); loginWindow.ShowDialog(); } }
public async Task <ActionResult <Commander> > Post(CommanderViewModel commander) { if (commander == null) { return(BadRequest()); } Commander newCommander = new Commander { LastName = commander.LastName, RankId = commander.RankId }; db.Commanders.Add(newCommander); await db.SaveChangesAsync(); return(Ok(newCommander)); }
public ActionResult Create(CommanderViewModel cv) { if (cv.Idcom != 0) { var objet_modifier = com.Commanders.Where(x => x.Idcom == cv.Idcom).First(); objet_modifier.Idcom = (int)cv.Idcom; objet_modifier.quantite = (int)cv.quantite; objet_modifier.id_ouvrage = (int)cv.id_ouvrage; objet_modifier.destinataire = cv.destinataire; objet_modifier.date_envoi = (DateTime)cv.date_envoi; objet_modifier.datecommande = (DateTime)cv.datecommande; objet_modifier.ville_livraison = cv.ville_livraison; objet_modifier.remise = (float)cv.Remise; objet_modifier.pays_livraison = cv.pays_livraison; objet_modifier.Prix = (float)cv.Prix; objet_modifier.Total = (float)cv.Total; } else { com.Commanders.Add(new Models.Commander { id_ouvrage = (int)cv.id_ouvrage, Total = (float)cv.Total, date_envoi = (DateTime)cv.date_envoi, datecommande = (DateTime)cv.datecommande, remise = (float)cv.Remise, pays_livraison = cv.pays_livraison, destinataire = cv.destinataire, Prix = (float)cv.Prix, ville_livraison = cv.ville_livraison, quantite = (int)cv.quantite }); } com.SaveChanges(); return(RedirectToAction("Acheter")); }
public ActionResult Create(int?Idcom) { CommanderViewModel oo = new CommanderViewModel(); if (Idcom != null) { var objet_modifier = com.Commanders.Where(x => x.Idcom == Idcom).First(); oo.Idcom = (int)objet_modifier.Idcom; oo.Prix = (float)objet_modifier.Prix; oo.quantite = (int)objet_modifier.quantite; oo.Remise = (float)objet_modifier.remise; //omod.id_type =(int) objet_modifier.id_type; oo.Total = (float)objet_modifier.Total; oo.ville_livraison = objet_modifier.ville_livraison; oo.pays_livraison = objet_modifier.pays_livraison; oo.datecommande = (DateTime)objet_modifier.datecommande; oo.date_envoi = (DateTime)objet_modifier.date_envoi; oo.destinataire = objet_modifier.destinataire; oo.id_ouvrage = (int)objet_modifier.id_ouvrage; } return(View(oo)); }
public void TestCopy([FromBody] CommanderViewModel commanderVM) { }
public async Task <IActionResult> Edit(int id, CommanderViewModel commanderVM) { if (id != commanderVM.id) { return(NotFound()); } Commander commander = new Commander() { id = commanderVM.id, Name = commanderVM.Name, Surname = commanderVM.Surname, Paronymic = commanderVM.Paronymic, DateOfBirth = commanderVM.DateOfBirth, Position = commanderVM.Position, AdditionalInformation = commanderVM.AdditionalInformation, WeekId = commanderVM.WeekId, Image = commanderVM.Image, BattleFrontId = commanderVM.BattleFrontId, ArmyId = commanderVM.ArmyId, CorpsId = commanderVM.CorpsId, DivisionId = commanderVM.DivisionId, BrigadeId = commanderVM.BrigadeId, RegimentId = commanderVM.RegimentId, BattalionId = commanderVM.BattalionId }; if (ModelState.IsValid) { if (commanderVM.File != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(commanderVM.File.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)commanderVM.File.Length); } // установка массива байтов commander.Image = imageData; try { _context.Update(commander); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommanderExists(commander.id)) { return(NotFound()); } else { throw; } } } else if (commanderVM.File == null) { commander.Image = commanderVM.Image; try { _context.Update(commander); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommanderExists(commander.id)) { return(NotFound()); } else { throw; } } } return(RedirectToAction(nameof(Index))); } ViewData["WeekId"] = new SelectList(_context.Week, "WeekId", "WeekId", commander.WeekId); return(View(commander)); }