Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Това е екшъна
- public IHttpResponse Edit(AddGameViewModel model)
- {
- this.ValidateModel(model);
- var id = this.Request.UrlParameters["gameId"];
- this.Service.UpdateGame(int.Parse(id), model);
- return this.RedirectResponse("/admin/games/list");
- }
- // Това е в сървиса
- public void UpdateGame(int id, AddGameViewModel model)
- {
- using (var db = new GameStoreContext())
- {
- var game = db.Games.FirstOrDefault(g => g.Id == id);
- game.Title = model.Title;
- game.VideoId = model.VideoId;
- game.ImageUrl = model.ImageUrl;
- game.Size = model.Size;
- game.Price = model.Price;
- game.Description = model.Description;
- game.ReleaseDate = model.ReleaseDate;
- db.SaveChanges();
- }
- }
- // Това е за раутовете
- appRouteConfig.AnonymousPaths.Add("/admin/games/edit/{(?<gameId>[0-9]+)}");
- appRouteConfig
- .Post("/admin/games/edit/{(?<gameId>[0-9]+)}", req => new AdminController(req).Edit(new AddGameViewModel()
- {
- Title = req.FormData["title"],
- Description = req.FormData["description"],
- ImageUrl = req.FormData["imageUrl"],
- Price = decimal.Parse(req.FormData["price"]),
- Size = float.Parse(req.FormData["size"]),
- VideoId = req.FormData["videoUrl"],
- ReleaseDate = DateTime.ParseExact(req.FormData["releaseDate"], "yyyy-MM-dd", CultureInfo.InvariantCulture)
- }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement