Esempio n. 1
0
 public void UpdateRating(PegiRating pegi)
 {
     if (pegi != null)
     {
         Context.Entry(pegi).State = EntityState.Modified;
     }
 }
Esempio n. 2
0
 public void CreateRating(PegiRating pegi)
 {
     if (pegi != null)
     {
         Context.PegiRates.Add(pegi);
     }
 }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }