Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var isAuthorzed = await _authorizationService
                              .AuthorizeAsync(User, SparePart, Operations.Create);

            if (!isAuthorzed.Succeeded)
            {
                return(new ChallengeResult());
            }

            await _sparePartService.CreateAsync(SparePart);

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> PostSparePart([FromBody] SparePart sparePart)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var isAuthorized = await _authorizationService
                               .AuthorizeAsync(User, sparePart, Operations.Create);

            if (!isAuthorized.Succeeded)
            {
                return(Unauthorized());
            }

            await _sparePartService.CreateAsync(sparePart);

            return(CreatedAtAction("GetSparePart", new { id = sparePart.SparePartId }, sparePart));
        }