示例#1
0
        public async Task <IActionResult> OnPostAsync(int venueId)
        {
            if (!ModelState.IsValid)
            {
                await FetchData(venueId).ConfigureAwait(false);

                return(this.TurboPage());
            }

            if (!await FetchData(venueId).ConfigureAwait(false))
            {
                return(this.RedirectToPage("/Index"));
            }

            var coords = await coordinates.GetCoordinates(Input.VenuePostCode ?? "").ConfigureAwait(false);

            string latitude  = null;
            string longitude = null;

            int?selectedImageId = Input.ImageId == null ? null : int.Parse(Input.ImageId) as int?;

            if (Input.ImageId == null || !Images.Exists(i => i.ImageId == selectedImageId))
            {
                selectedImageId = null;
            }

            if (coords.HasValue)
            {
                latitude  = coords.Value.Latitude.ToString();
                longitude = coords.Value.Longitude.ToString();
            }

            var servingType = ServingTypeHelper.ValidateServingType(Input.ServingType) ? Input.ServingType : 0;

            var patch = new VenuePatch
            {
                ResourceId = venueId,
                VenueName  = new PatchOperation <string> {
                    Operation = OperationKind.Update, Value = Input.VenueName
                },
                VenueAddress = new PatchOperation <string> {
                    Operation = OperationKind.Update, Value = Input.VenueAddress
                },
                VenueAddress2 = new PatchOperation <string> {
                    Operation = OperationKind.Update, Value = Input.VenueAddress2
                },
                VenueAddress3 = new PatchOperation <string> {
                    Operation = OperationKind.Update, Value = Input.VenueAddress3
                },
                VenueCounty = new PatchOperation <string> {
                    Operation = OperationKind.Update, Value = Input.VenueCounty
                },
                VenuePostCode = new PatchOperation <string> {
                    Operation = OperationKind.Update, Value = Input.VenuePostCode
                },
                VenuePhone = new PatchOperation <string> {
                    Operation = OperationKind.Update, Value = Input.VenuePhone
                },
                VenueContact = new PatchOperation <string> {
                    Operation = OperationKind.Update, Value = Input.VenueContact
                },
                VenueDescription = new PatchOperation <string> {
                    Operation = OperationKind.Update, Value = Input.VenueDescription
                },
                VenueLatitude = new PatchOperation <string> {
                    Operation = OperationKind.Update, Value = latitude
                },
                VenueLongitude = new PatchOperation <string> {
                    Operation = OperationKind.Update, Value = longitude
                },
                ServingType = new PatchOperation <int> {
                    Operation = OperationKind.Update, Value = servingType
                }
            };

            if (selectedImageId != null)
            {
                patch.ImageId = new PatchOperation <int> {
                    Operation = OperationKind.Update, Value = selectedImageId.Value
                };
            }

            if (Input.VenueProgress != null && Role.CanAdministerSystem)
            {
                patch.Progress = new PatchOperation <int> {
                    Operation = OperationKind.Update, Value = Input.VenueProgress.Value
                };
            }

            var result = await venues.UpdateVenue(patch)
                         .OnSuccess(() => tags.ReplaceVenueTags(venueId, (Input.Tags ?? "").Trim().Split(',').ToList())
                                    .OnSuccess(() => venueDocuments.ReplaceVenueDocuments(venueId, (Input.DocumentIds ?? new List <string>()).Select(id => new VenueDocument {
                VenueId = venueId, DocumentId = int.Parse(id)
            }).ToList())))
                         .OnSuccess(() => venues.UpdateVenueCoordinates(venueId))
                         .ConfigureAwait(false);

            if (result.IsSuccess)
            {
                await UpdateVenuesWithExternalPaymentProvider(Venue.CompanyId).ConfigureAwait(false);
                await UpdateVenueOpeningTimes().ConfigureAwait(false);

                return(this.RedirectToPage("/Venue", new
                {
                    venueId
                }));
            }
            else
            {
                return(this.Page());
            }
        }