public IActionResult Add(AddArmorFormModel armor) { var(isClassCorrect, classEnum) = this.armorsService.IsCharacterClassNameValid(armor.Class); if (!isClassCorrect) { this.ModelState.AddModelError(nameof(armor.Class), "Character class does not exist!"); return(View(armor)); } if (!this.ModelState.IsValid) { return(View(armor)); } var armorId = this.armorsService.Create( armor.Name, armor.IntrinsicName, armor.IntrinsicDescription, classEnum, armor.ImageUrl, this.User.GetId()); return(RedirectToAction( nameof(ArmorsController.Details), nameof(ArmorsController).RemoveControllerFromString(), new { id = armorId })); }
public IActionResult Edit(string id) { var armor = this.armorsService.GetById(id); if (armor == null) { return(NotFound()); } if (this.User.GetId() != armor.UserId && !this.User.IsInRole(adminRoleName)) { return(Unauthorized()); } var model = new AddArmorFormModel { Name = armor.Name, IntrinsicName = armor.IntrinsicName, IntrinsicDescription = armor.IntrinsicDescription, ImageUrl = armor.ImageUrl, Class = armor.ClassName, }; return(View(model)); }
public IActionResult Edit(string id, AddArmorFormModel newArmor) { var armor = this.armorsService.GetIdAndUserIdById(id); if (armor == null) { return(NotFound()); } if (this.User.GetId() != armor.UserId && !this.User.IsInRole(adminRoleName)) { return(Unauthorized()); } var(isClassCorrect, classEnum) = this.armorsService.IsCharacterClassNameValid(newArmor.Class); if (!isClassCorrect) { this.ModelState.AddModelError(nameof(newArmor.Class), "Character class does not exist"); } if (!this.ModelState.IsValid) { return(View(newArmor)); } this.armorsService.Edit( armor.Id, newArmor.Name, newArmor.IntrinsicName, newArmor.IntrinsicDescription, classEnum, newArmor.ImageUrl); return(RedirectToAction( nameof(ArmorsController.Details), nameof(ArmorsController).RemoveControllerFromString(), new { id = armor.Id })); }