public async Task <IActionResult> Edit(int id, [Bind("NewsId,Header,ShortStory,MainStory")] News news) { if (id != news.NewsId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(news); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NewsExists(news.NewsId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(news)); }
public async Task <IActionResult> Edit(int id, ProjectViewModel model) { if (id != model.ProjectID) { return(NotFound()); } if (ModelState.IsValid) { try { var project = new Project { SailboatProject = model.SailboatProject, LadyaProject = model.LadyaProject, KaterProject = model.KaterProject, MaketDesign = model.MaketDesign, MaketMuseum = model.MaketMuseum, MaketCinema = model.MaketCinema, MaketStudy = model.MaketStudy, SailboatHistorical = model.SailboatHistorical, SailboatStudy = model.SailboatStudy, Shvertbot = model.Shvertbot, Yacht = model.Yacht, LadyaSail = model.LadyaSail, LadyaRow = model.LadyaRow, KaterPass = model.KaterPass, KaterFish = model.KaterFish, KaterCabin = model.KaterCabin, Motosailer = model.Motosailer, Botik = model.Botik, KaterRow = model.KaterRow, BoatYal = model.BoatYal, BoatTraditional = model.BoatTraditional, BoatSail = model.BoatSail, BoatRow = model.BoatRow, ProjectID = model.ProjectID, Name = model.Name, Length = model.Length, Deep = model.Deep, Description = model.Description, Mass = model.Mass, NumberOfOars = model.NumberOfOars, EnginePower = model.EnginePower, PassengerCap = model.PassengerCap, FuelCap = model.FuelCap, FreshWaterCap = model.FreshWaterCap, SailArea = model.SailArea, SleepingAreas = model.SleepingAreas, Speed = model.Speed, Volume = model.Volume, Windth = model.Windth, //ShipSheme = project.ShipSheme, //MainFoto = proj.MainFoto }; if (model.ShipSheme != null) { using (var memoryStream = new MemoryStream()) { await model.ShipSheme.CopyToAsync(memoryStream); project.ShipSheme = memoryStream.ToArray(); } } else { var proj = _context.Project.Single(f => f.ProjectID.Equals(id)); project.ShipSheme = proj.ShipSheme; } if (model.MainFoto != null) { using (var memoryStream = new MemoryStream()) { await model.MainFoto.CopyToAsync(memoryStream); project.MainFoto = memoryStream.ToArray(); } } else { var proj = _context.Project.Single(f => f.ProjectID.Equals(id)); project.MainFoto = proj.MainFoto; } _context.Update(project); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProjectExists(model.ProjectID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }