public async Task <IActionResult> AddClaims(ClaimTypeViewModel claimType) { await _claimTypeRepository.Add(new ClaimType { ApplicationType = ClaimTypeEnum.User, Name = claimType.Name }); await _claimTypeRepository.SaveChanges(); return(View(model: claimType)); }
public ClaimTypeViewModel GetClaimTypeViewModel(IList <ClaimTypeEnumViewModel> allTypes) { var vm = new ClaimTypeViewModel { AllTypeValues = allTypes }; return(vm); }
public async Task <Guid> CreateAsync(ClaimTypeViewModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var param = ToParam(model); return(await _service.CreateAsync(param)); }
public async Task <IActionResult> UpdateAsync([FromBody] ClaimTypeViewModel model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _service.UpdateAsync(model); return(NoContent()); }
public async Task <IActionResult> CreateAsync([FromBody] ClaimTypeViewModel model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _service.CreateAsync(model); return(Created($"claimtypes/{result}", result)); }
public async Task UpdateAsync(ClaimTypeViewModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!model.Id.HasValue) { throw new InvalidOperationException(nameof(model.Id)); } var param = ToParam(model); await _service.UpdateAsync(param); }
public async Task UpdateAsync_WithInvalidModel_ReturnsBadRequest() { // Arrange var controller = GetController(); var model = new ClaimTypeViewModel { // Name // required // ClaimValueType // required }; // ModelState must be manually adjusted controller.ModelState.AddModelError(string.Empty, "Name required!"); // Act var result = await controller.UpdateAsync(model); // Assert Assert.NotNull(result); Assert.IsType <BadRequestObjectResult>(result); }
public ActionResult Create(ClaimTypeViewModel claimTypeViewModel) { if (ModelState.IsValid) { var claimTypeModel = m_mapper.Map <ClaimTypeModel>(claimTypeViewModel); var result = m_claimTypeManager.CreateClaimType(claimTypeModel); if (!result.HasError) { return(RedirectToAction(nameof(View), new { id = result.Result })); } ModelState.AddModelError(result.Error.Message); } var viewModel = ViewModelBuilder.BuildClaimTypeViewModel(ModelState, claimTypeViewModel); return(View(viewModel)); }
public ClaimTypeViewModel BuildClaimTypeViewModel(ModelStateDictionary modelState, ClaimTypeViewModel claimTypeViewModel = null) { var claimTypesEnums = m_claimTypeManager.GetAllClaimTypeEnums(); if (claimTypesEnums.HasError) { modelState.AddModelError(claimTypesEnums.Error.Message); } var claimTypeEnumViewModels = m_mapper.Map <IList <ClaimTypeEnumViewModel> >(claimTypesEnums.Result); if (claimTypeViewModel == null) { return(m_viewModelFactory.GetClaimTypeViewModel(claimTypeEnumViewModels)); } claimTypeViewModel.AllTypeValues = claimTypeEnumViewModels; return(claimTypeViewModel); }
private static ClaimTypeParam ToParam(ClaimTypeViewModel model) => SimpleMapper.From <ClaimTypeViewModel, ClaimTypeParam>(model);