Пример #1
0
        // GET: Samourais/Create
        public ActionResult Create()
        {
            SamouraiVM vm         = new SamouraiVM();
            List <int> armeOccupe = db.Samourais.Where(y => y.Arme != null).Select(x => x.Arme.Id).ToList();

            vm.Armes         = db.Armes.Where(x => !armeOccupe.Contains(x.Id)).ToList();
            vm.ArtMartialsVM = db.ArtMartials.ToList();

            return(View(vm));
        }
Пример #2
0
 public ActionResult Create(SamouraiVM vm)
 {
     if (ModelState.IsValid)
     {
         vm.Samourai.Arme = db.Armes.Find(vm.ArmeId);
         foreach (var item in vm.ArtMartialsIds)
         {
             vm.Samourai.ArtMartials.Add(db.ArtMartials.Find(item));
         }
         db.Samourais.Add(vm.Samourai);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     vm.Armes         = db.Armes.ToList();
     vm.ArtMartialsVM = db.ArtMartials.ToList();
     return(View(vm));
 }
Пример #3
0
        // GET: Samourais/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Samourai samourai = db.Samourais.Find(id);

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

            SamouraiVM vm = new SamouraiVM();

            vm.Samourai = samourai;


            return(View(vm));
        }
Пример #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());
            }
            SamouraiVM vm = new SamouraiVM();

            vm.Samourai      = samourai;
            vm.Armes         = db.Armes.ToList();
            vm.ArtMartialsVM = db.ArtMartials.ToList();
            Arme arme = new Arme();

            if (samourai.Arme != null)
            {
                vm.ArmeId = samourai.Arme.Id;
            }

            if (samourai.ArtMartials.Count > 0)
            {
                foreach (var item in samourai.ArtMartials)
                {
                    vm.ArtMartialsIds.Add(item.Id);
                }
            }



            return(View(vm));
        }