public ActionResult UpdateRating(Guid? id) { if (id.HasValue) { var entity = PegiManager.FindRatingById(id.Value); var model = new PegiRatingViewModel { Id = entity.Id, IconLink = entity.IconLink, Name = entity.Name, Content = PegiManager.PegiContent.ToSelectableList(entity.Content.ToList()) }; return View("UpdateRating", model); } return RedirectToAction("Index"); }
public ActionResult UpdateRating(PegiRatingViewModel model) { if (ModelState.IsValid) { var pegi = new PegiRating { Id = model.Id, Name = model.Name, IconLink = model.IconLink }; PegiRating pr = PegiManager.FindRatingById(model.Id); foreach (var ctnt in model.Content) { Guid guid = new Guid(ctnt.Value); var temp = PegiManager.FindContentById(new Guid(ctnt.Value)); if (ctnt.Selected) { if (!pr.Content.Any(c => c.Id == guid)) { pr.Content.Add(temp); temp.Rates.Add(pr); } } else { if(pr.Content.Any(c => c.Id == guid)) { pr.Content.Remove(temp); temp.Rates.Remove(pr); } } } PegiManager.UpdateRating(pr); PegiManager.Save(); return RedirectToAction("Index"); } return View(model); }
public ActionResult CreateRating(PegiRatingViewModel model) { if (ModelState.IsValid) { var content = new List<PegiContent>(); foreach (var ctnt in model.Content) { if (ctnt.Selected) { content.Add(PegiManager.FindContentById(new Guid(ctnt.Value))); } } var pegi = new PegiRating { Name = model.Name, IconLink = model.IconLink, Content = content }; PegiManager.CreateRating(pegi); PegiManager.Save(); return RedirectToAction("Index"); } return View(model); }