public async Task <ActionResult <Marina> > PostSpot(Marina marina) { if (marina.MarinaId != 0 || marina.Location?.LocationId != 0) { BadRequest("Do not set the ID"); } await _marinaService.Create(marina); await _marinaService.Save(); return(CreatedAtAction("GetSpot", new { id = marina.MarinaId }, marina)); }
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; } }