Advertisement
Guest User

Edit

a guest
Oct 19th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. // Това е екшъна      
  2.       public IHttpResponse Edit(AddGameViewModel model)
  3.         {
  4.             this.ValidateModel(model);
  5.             var id = this.Request.UrlParameters["gameId"];
  6.             this.Service.UpdateGame(int.Parse(id), model);
  7.             return this.RedirectResponse("/admin/games/list");
  8.         }
  9. // Това е в сървиса
  10.       public void UpdateGame(int id, AddGameViewModel model)
  11.         {
  12.             using (var db = new GameStoreContext())
  13.             {
  14.               var game =  db.Games.FirstOrDefault(g => g.Id == id);
  15.                 game.Title = model.Title;
  16.                 game.VideoId = model.VideoId;
  17.                 game.ImageUrl = model.ImageUrl;
  18.                 game.Size = model.Size;
  19.                 game.Price = model.Price;
  20.                 game.Description = model.Description;
  21.                 game.ReleaseDate = model.ReleaseDate;
  22.  
  23.                 db.SaveChanges();
  24.             }
  25.         }
  26. // Това е за раутовете
  27.  appRouteConfig.AnonymousPaths.Add("/admin/games/edit/{(?<gameId>[0-9]+)}");
  28.  
  29.    appRouteConfig
  30.                 .Post("/admin/games/edit/{(?<gameId>[0-9]+)}", req => new AdminController(req).Edit(new AddGameViewModel()
  31.                 {
  32.                     Title = req.FormData["title"],
  33.                     Description = req.FormData["description"],
  34.                     ImageUrl = req.FormData["imageUrl"],
  35.                     Price = decimal.Parse(req.FormData["price"]),
  36.                     Size = float.Parse(req.FormData["size"]),
  37.                     VideoId = req.FormData["videoUrl"],
  38.                     ReleaseDate = DateTime.ParseExact(req.FormData["releaseDate"], "yyyy-MM-dd", CultureInfo.InvariantCulture)
  39.                 }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement