예제 #1
0
 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");
 }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }