public ActionResult Create([Bind(Include = "ID,Name,Price,BeastID")]
                                   AccessoryVM accessory)
        {
            if (ModelState.IsValid)
            {
                _accessRepo.Add(accessory.Accessory);
                _accessRepo.Complete();
                return(RedirectToAction("Index"));
            }

            ViewBag.BeastID = new SelectList(_accessRepo.ContextDB().Beast, "ID", "Name", accessory.BeastID);
            return(View(accessory));
        }
Beispiel #2
0
        public IActionResult Post(Gear gear)
        {
            var currentUser = GetCurrentUserProfile();

            gear.UserProfileId = currentUser.Id;

            try
            {
                _gearRepository.Add(gear);
                foreach (Accessory accessory in gear.Accessories)
                {
                    accessory.GearId = gear.Id;
                    _accessoryRepository.Add(accessory);
                }

                return(CreatedAtAction("Get", new { id = gear.Id }, gear));
            }
            catch
            {
                return(StatusCode(500));
            }
        }