コード例 #1
0
        public IActionResult Add(AddWeaponFormModel weapon)
        {
            if (!this.weaponsService.WeaponClassExists(weapon.ClassId))
            {
                this.ModelState.AddModelError(nameof(weapon.ClassId), "Weapon class does not exist");
            }

            if (!this.ModelState.IsValid)
            {
                weapon.Classes = this.weaponsService.AllClasses();
                return(View(weapon));
            }

            var weaponId = this.weaponsService.Create(
                weapon.Name,
                weapon.IntrinsicName,
                weapon.IntrinsicDescription,
                weapon.CatalystName,
                weapon.CatalystCompletionRequirement,
                weapon.CatalystEffect,
                weapon.ClassId,
                weapon.ImageUrl,
                this.User.GetId());

            return(RedirectToAction(
                       nameof(WeaponsController.Details),
                       nameof(WeaponsController).RemoveControllerFromString(),
                       new { id = weaponId }));
        }
コード例 #2
0
        public IActionResult Edit(string id)
        {
            var weapon = this.weaponsService.GetById(id);

            if (weapon == null)
            {
                return(NotFound());
            }

            if (this.User.GetId() != weapon.UserId && !this.User.IsInRole(adminRoleName))
            {
                return(Unauthorized());
            }

            var model = new AddWeaponFormModel
            {
                Name                          = weapon.Name,
                IntrinsicName                 = weapon.IntrinsicName,
                IntrinsicDescription          = weapon.IntrinsicDescription,
                CatalystName                  = weapon.CatalystName,
                CatalystCompletionRequirement = weapon.CatalystCompletionRequirement,
                CatalystEffect                = weapon.CatalystEffect,
                ImageUrl                      = weapon.ImageUrl,
                ClassId                       = weapon.ClassId,
                Classes                       = this.weaponsService.AllClasses()
            };

            return(View(model));
        }
コード例 #3
0
        public IActionResult Edit(string id, AddWeaponFormModel newWeapon)
        {
            var weapon = this.weaponsService.GetIdAndUserIdById(id);

            if (weapon == null)
            {
                return(NotFound());
            }

            if (this.User.GetId() != weapon.UserId && !this.User.IsInRole(adminRoleName))
            {
                return(Unauthorized());
            }

            if (!this.weaponsService.WeaponClassExists(newWeapon.ClassId))
            {
                this.ModelState.AddModelError(nameof(newWeapon.ClassId), "Weapon class does not exist");
            }

            if (!this.ModelState.IsValid)
            {
                newWeapon.Classes = this.weaponsService.AllClasses();
                return(View(newWeapon));
            }

            this.weaponsService.Edit(
                weapon.Id,
                newWeapon.Name,
                newWeapon.IntrinsicName,
                newWeapon.IntrinsicDescription,
                newWeapon.CatalystName,
                newWeapon.CatalystCompletionRequirement,
                newWeapon.CatalystEffect,
                newWeapon.ClassId,
                newWeapon.ImageUrl);

            return(RedirectToAction(
                       nameof(WeaponsController.Details),
                       nameof(WeaponsController).RemoveControllerFromString(),
                       new { id = weapon.Id }));
        }