Пример #1
0
        public async Task <IActionResult> Create([Bind("MarinaId, SpotNumber, Available, MaxWidth, MaxLength, MaxDepth, Price")] Spot spot)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    ViewData["MarinaId"] = await MarinaList();

                    return(View(spot));
                }

                // If user has chosen a location for the spot by using the
                // Leaflet map
                if (SpotLocationIsSelected())
                {
                    // Create related data (Location) for the Spot and assign
                    // the newly created Location to the Spot
                    var location = GetLocationData();
                    await _spotService.CreateWithLocation(spot, location);
                }
                else
                {
                    await _spotService.Create(spot);
                }

                await _spotService.Save();

                return(RedirectToAction(nameof(Index)));
            }
            catch (BusinessException exception)
            {
                ModelState.TryAddModelError(exception.Key, exception.Message);
                throw;
            }
        }
Пример #2
0
        public async Task <IActionResult> PutSpot(int id, Spot spot)
        {
            if (id != spot.SpotId)
            {
                return(BadRequest());
            }

            var isAuthorized = await _authorizationService.AuthorizeAsync(User, spot, Operation.Update);

            if (isAuthorized.Succeeded)
            {
                _spotService.Update(spot);
                try
                {
                    await _spotService.Save();
                }
                catch (BusinessException ex)
                {
                    BadRequest(ex);
                }
            }

            return(NoContent());
        }