public async Task <IActionResult> Create([Bind("Name, Description, Facilities")] Marina marina) { try { // Reload the page if the model is invalid if (!ModelState.IsValid) { return(View(marina)); } // Set the marina's marinaOwner id to logged user var person = await _userManager.GetUserAsync(User); var marinaOwnerId = _userService.GetMarinaOwnerFromPerson(person).MarinaOwnerId; marina.MarinaOwnerId = marinaOwnerId; if (MarinaLocationIsSelected()) { var marinaLocation = GetLocationFormData(); await _marinaService.CreateWithLocation(marina, marinaLocation); } else { await _marinaService.Create(marina); } await _marinaService.Save(); // Return to index if successful return(RedirectToAction(nameof(Index))); } catch (BusinessException exception) { Console.WriteLine(exception); throw; } }
public async Task <IActionResult> PutMarina(int id, Marina marina) { if (id != marina.MarinaId) { return(BadRequest()); } var isAuthorized = await _authorizationService.AuthorizeAsync(User, marina, Operation.Update); if (isAuthorized.Succeeded) { _marinaService.Update(marina); try { await _marinaService.Save(); } catch (BusinessException ex) { BadRequest(ex); } } return(NoContent()); }