コード例 #1
0
        public ActionResult Create(CreateSamouraiView CNewS)
        {
            if (ModelState.IsValid)
            {
                if (CNewS.IdArmes != null)
                {
                    Arme arme = db.Armes.FirstOrDefault(i => i.Id == CNewS.IdArmes);
                    CNewS.Samourai.Arme = arme;
                }
                else
                {
                    CNewS.Samourai.Arme = null;
                }
                if (CNewS.IdArtsMartiaux.Count > 0)
                {
                    CNewS.Samourai.ArtMartials = db.ArtMartials.Where(x => CNewS.IdArtsMartiaux.Contains(x.Id)).ToList();
                }
                else
                {
                    CNewS.Samourai.ArtMartials = null;
                }
                CNewS.Samourai.Potentiel = (CNewS.Samourai.Force + CNewS.Samourai.Arme.Degats) * (CNewS.Samourai.ArtMartials.Count + 1);
                db.Samourais.Add(CNewS.Samourai);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(CNewS));
        }
コード例 #2
0
        // GET: Samourais/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Samourai samourai = db.Samourais.Find(id);

            if (samourai == null)
            {
                return(HttpNotFound());
            }

            CreateSamouraiView CNewS = new CreateSamouraiView
            {
                Samourai = new Samourai
                {
                    Id          = samourai.Id,
                    Nom         = samourai.Nom,
                    Force       = samourai.Force,
                    Arme        = samourai.Arme,
                    ArtMartials = samourai.ArtMartials,
                    Potentiel   = samourai.Potentiel
                }
            };

            return(View(CNewS));
        }
コード例 #3
0
 public ActionResult Edit(CreateSamouraiView CEditS)
 {
     if (ModelState.IsValid)
     {
         Samourai samourai = db.Samourais.Find(CEditS.Samourai.Id);
         samourai.Nom   = CEditS.Samourai.Nom;
         samourai.Force = CEditS.Samourai.Force;
         if (CEditS.IdArtsMartiaux.Count > 0)
         {
             samourai.ArtMartials = db.ArtMartials.Where(x => CEditS.IdArtsMartiaux.Contains(x.Id)).ToList();
         }
         else
         {
             samourai.ArtMartials = null;
         }
         if (CEditS.IdArmes != null)
         {
             Arme arme = db.Armes.FirstOrDefault(i => i.Id == CEditS.IdArmes);
             samourai.Arme      = arme;
             samourai.Potentiel = (samourai.Force + samourai.Arme.Degats) * (samourai.ArtMartials.Count + 1);
         }
         else
         {
             samourai.Arme = null;
         }
         db.Entry(samourai).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(CEditS));
 }
コード例 #4
0
        // GET: Samourais/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Samourai samourai = db.Samourais.Find(id);

            if (samourai == null)
            {
                return(HttpNotFound());
            }
            CreateSamouraiView CNewS = new CreateSamouraiView
            {
                Samourai = new Samourai
                {
                    Id    = samourai.Id,
                    Nom   = samourai.Nom,
                    Force = samourai.Force,
                    Arme  = samourai.Arme
                }
            };

            List <int> ListIdArme = db.Samourais.Where(a => a.Arme != null).Select(x => x.Arme.Id).ToList();

            CNewS.ListeArmes     = db.Armes.Where(x => !ListIdArme.Contains(x.Id)).ToList();
            CNewS.IdArtsMartiaux = db.ArtMartials.Select(x => x.Id).ToList();
            CNewS.ArtMartials    = db.ArtMartials.ToList();
            return(View(CNewS));
        }
コード例 #5
0
        public ActionResult DeleteConfirmed(CreateSamouraiView delateO)
        {
            Samourai samourai = db.Samourais.Find(delateO.Samourai.Id);

            db.Samourais.Remove(samourai);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #6
0
        // GET: Samourais/Create
        public ActionResult Create()
        {
            CreateSamouraiView CNewS      = new CreateSamouraiView();
            List <int>         ListIdArme = db.Samourais.Where(a => a.Arme != null).Select(x => x.Arme.Id).ToList();

            CNewS.ListeArmes  = db.Armes.Where(x => !ListIdArme.Contains(x.Id)).ToList();
            CNewS.ArtMartials = db.ArtMartials.ToList();
            return(View(CNewS));
        }