Example #1
0
        public virtual IActionResult UpdateVenue([FromBody] Venue venue)
        {
            var result = _venueRepository.UpdateVenue(venue);

            if (result == null)
            {
                return(BadRequest());
            }
            return(new ObjectResult(result));
        }
Example #2
0
        private async Task <IActionResult> UpdateVerification(int venueId, int status)
        {
            Employee = await userManager.GetUserAsync(User).ConfigureAwait(false);

            Role = await roleManager.FindByIdAsync(Employee.RoleId.ToString()).ConfigureAwait(false);

            if (!Role.CanAdministerSystem)
            {
                return(RedirectToPage("/Index"));
            }

            var getResult = (await venues.FetchVenue(venueId).ConfigureAwait(false))
                            .Ensure(e => e.HasValue, "Venue found")
                            .OnSuccess(e => e.Value);

            if (!getResult.IsSuccess)
            {
                return(RedirectToPage("/Index"));
            }

            var result = await venues.UpdateVenue(new VenuePatch {
                ResourceId         = venueId,
                VerificationStatus = new PatchOperation <int> {
                    Operation = OperationKind.Update, Value = status
                }
            }).ConfigureAwait(false);

            if (result.IsSuccess)
            {
                return(Redirect(Request.GetEncodedUrl()));
            }
            else
            {
                return(RedirectToPage("/Index"));
            }
        }
Example #3
0
        private async Task SynchVenuesWithExternalPaymentProvider(string accessToken, Company company)
        {
            if (company == null)
            {
                return;
            }

            try
            {
                var client = new SquareClient.Builder()
                             .Environment(_settings.Connection.SquarePaymentsSandbox ? Square.Environment.Sandbox : Square.Environment.Production)
                             .AccessToken(accessToken)
                             .Build();

                ListLocationsResponse result = await client.LocationsApi.ListLocationsAsync().ConfigureAwait(false);

                var companyVenues = await _venues.FetchCompanyVenues(company.CompanyId, 0, int.MaxValue)
                                    .OnSuccess(c => c.Value.ToList())
                                    .ConfigureAwait(true);

                if (companyVenues.IsSuccess)
                {
                    foreach (var item in companyVenues.Value)
                    {
                        try
                        {
                            var matchedLocation = result.Locations
                                                  .FirstOrDefault(
                                x => NormaliseString(x.Name) == NormaliseString(item.VenueName) &&
                                NormaliseString(x.Address.PostalCode) == NormaliseString(item.VenuePostCode));

                            // need to find a match in Square location
                            if (matchedLocation != null)
                            {
                                if (string.IsNullOrWhiteSpace(item.ExternalLocationId) && matchedLocation != null)
                                {
                                    // We have a match and need to update local Database
                                    await _venues.UpdateVenue(new VenuePatch
                                    {
                                        ResourceId         = item.VenueId,
                                        ExternalLocationId = new PatchOperation <string> {
                                            Operation = OperationKind.Update, Value = matchedLocation.Id
                                        },
                                    }).ConfigureAwait(false);
                                }
                            }
                            else if (matchedLocation == null)
                            {
                                // we have a location in our system that does not exist in sqaure. Need to add one
                                var createLocation = new CreateLocationRequest(new Location(
                                                                                   name: item.VenueName,
                                                                                   address:
                                                                                   new Address(
                                                                                       addressLine1: string.IsNullOrWhiteSpace(item.VenueAddress) ? "Not supplied" : item.VenueAddress,
                                                                                       addressLine2: item.VenueAddress2,
                                                                                       addressLine3: item.VenueAddress3,
                                                                                       postalCode: string.IsNullOrWhiteSpace(item.VenuePostCode) ? "Not supplied" : item.VenuePostCode,
                                                                                       locality: string.IsNullOrWhiteSpace(item.VenueCounty) ? "Not supplied" : item.VenueCounty,
                                                                                       firstName: item.VenueContact),
                                                                                   status: "ACTIVE",
                                                                                   phoneNumber: GetVenuePhoneNumber(company, item)));

                                var newLocation = client.LocationsApi.CreateLocation(createLocation);

                                if (newLocation.Location != null)
                                {
                                    await _venues.UpdateVenue(new VenuePatch
                                    {
                                        ResourceId         = item.VenueId,
                                        ExternalLocationId = new PatchOperation <string> {
                                            Operation = OperationKind.Update, Value = newLocation.Location.Id
                                        },
                                    }).ConfigureAwait(false);
                                }
                            }
                        }
                        catch (ApiException e)
                        {
                            Logger.LogError(e, $"Failed to create business location for venue {item.VenueName}");
                        }
                    }
                }
            }
            catch (ApiException e)
            {
                Logger.LogError(e, $"Failed to connect to Square API");
            }
        }
Example #4
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());
            }
        }