예제 #1
0
        public static GymSearchListResponse searchGymsByCityImplementation(SearchGymRequest request)
        {
            GymSearchListResponse rv;

            using (var db = new UniversalGymEntities())
            {
                var searchRequest = new Data.SearchRequest
                {
                    SearchDate             = DateTime.Now,
                    UniqueDeviceIdentifier = request.uniqueDeviceId,
                };

                if (request.longitude != 0 && request.latitude != 0)
                {
                    searchRequest.Position = System.Data.Entity.Spatial.DbGeography.FromText(String.Format("POINT({0} {1})", request.longitude, request.latitude));
                }



                if (!request.city.Equals("NULL"))
                {
                    searchRequest.Request = request.city;
                }

                if (!request.state.Equals("NULL"))
                {
                    searchRequest.Request = searchRequest.Request + " " + request.state ?? "NO STATE";
                }

                var user = db.Users.SingleOrDefault(a => a.CurrentToken == request.authToken && a.UserId == request.accountId);
                if (user != null)
                {
                    searchRequest.UserId = user.UserId;
                }


                db.SearchRequests.Add(searchRequest);
                db.SaveChanges();



                // convert city, state to lat, long
                var target   = searchRequest.Request;
                var geocoded = Geocoder.GeoCodeAddress(target);
                if (geocoded != null)
                {
                    var cityLocation = System.Data.Entity.Spatial.DbGeography.FromText(
                        String.Format("POINT({0} {1})",
                                      geocoded.Longitude,
                                      geocoded.Latitude));


                    var gyms = db.Gyms.Where(w => w.Position != null).OrderBy(o => o.Position.Distance(cityLocation));
                    rv = GymSearchListHelper.createGymSearchListResponse(gyms, cityLocation.Latitude, cityLocation.Longitude);
                    if (user != null)
                    {
                        rv.credits = user.Credits;
                    }
                    else
                    {
                        rv.credits = 0;
                    }

                    var searchText = "DeviceId: "
                                     + request.uniqueDeviceId
                                     + Environment.NewLine;
                    if (searchRequest.User != null)
                    {
                        searchText = searchText
                                     + "User: "******"Request: "
                                 + searchRequest.Request;

                    SlackHelper.sendSearchChannel(searchText, request.latitude.ToString(), request.longitude.ToString());
                }
                else
                {
                    var searchText = "";
                    if (searchRequest.User != null)
                    {
                        searchText = searchText
                                     + "User: "******"Request: "
                                 + searchRequest.Request;

                    SlackHelper.sendSearchChannelNotFound(searchText);

                    rv = new GymSearchListResponse {
                        success = false,
                        status  = 400,
                        message = "Could not find location"
                    };
                    if (user != null)
                    {
                        rv.credits = user.Credits;
                    }
                    else
                    {
                        rv.credits = 0;
                    }
                }
            }
            return(rv);
        }
예제 #2
0
        public static GymDataResponse gymRegisterImplementation(RegisterGymRequest request)
        {
            if (String.IsNullOrWhiteSpace(request.gymName))
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please enter a gym name"
                });
            }
            else if (String.IsNullOrWhiteSpace(request.gymPhone))
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please enter a gym phone number"
                });
            }

            else if (String.IsNullOrWhiteSpace(request.contactName))
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please enter a contact name"
                });
            }
            else if (String.IsNullOrWhiteSpace(request.contactEmail))
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please enter an email"
                });
            }
            else if (String.IsNullOrWhiteSpace(request.contactPhone))
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please enter a phone number"
                });
            }
            else if (String.IsNullOrWhiteSpace(request.website))
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please enter a website"
                });
            }
            else if (String.IsNullOrWhiteSpace(request.address))
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please enter a street"
                });
            }
            else if (String.IsNullOrWhiteSpace(request.city))
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please enter a city"
                });
            }
            else if (String.IsNullOrWhiteSpace(request.state))
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please enter a state or province"
                });
            }
            else if (String.IsNullOrWhiteSpace(request.zip))
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please enter a zip code"
                });
            }
            else if (String.IsNullOrWhiteSpace(request.priceTier))
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please select one given of the price tiers"
                });
            }
            else if (String.IsNullOrWhiteSpace(request.password) || request.password.Length < 6)
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please enter a password greater than 5 characters"
                });
            }
            else if (String.IsNullOrWhiteSpace(request.website))
            {
                return(new GymDataResponse {
                    success = false, status = 200, message = "Please enter a website"
                });
            }
            if (MembershipHelper.emailAlreadyExists(request.contactEmail, Constants.GymRole))
            {
                return(new GymDataResponse {
                    success = false, status = 10, message = "Email already taken."
                });
            }


            var newGymGuid = MembershipHelper.createMembership(request.contactEmail, request.password, Constants.GymRole);

            using (var db = new UniversalGymEntities())
            {
                var state = db.TypeStates.FirstOrDefault(f => f.StateAbbreviation.ToLower() == request.state.ToLower()) ??
                            db.TypeStates.First(f => f.StateAbbreviation == "00");

                var address = new Data.Address()
                {
                    StreetLine1 = request.address,
                    City        = request.city,
                    Zip         = request.zip,
                    TypeStateId = state.TypeStateId
                };
                db.Addresses.Add(address);
                var publicContactInfo = new Data.ContactInfo
                {
                    AddressId = address.AddressId,
                    Phone     = request.gymPhone,
                };
                db.ContactInfoes.Add(publicContactInfo);
                db.SaveChanges();
                var ownerContactInfo = new Data.ContactInfo
                {
                    Email = request.contactEmail,
                    Phone = request.contactPhone,
                };
                db.ContactInfoes.Add(ownerContactInfo);
                db.SaveChanges();

                var gym = new Data.Gym
                {
                    CreditDollarValue = Constants.returnGymPay(request.priceTier),
                    PriceToCharge     = Constants.returnGymPrice(request.priceTier),
                    GymName           = request.gymName,
                    IsApproved        = false,
                    OwnerName         = request.contactName,
                    Url = request.website.Contains("://") ? request.website : "http://" + request.website,
                    PublicContactInfoId = publicContactInfo.ContactInfoId,
                    OwnerContactInfoId  = ownerContactInfo.ContactInfoId,
                    GymInfo             = "",
                    GymGuid             = newGymGuid,
                    ApplicationDate     = DateTime.UtcNow,
                    IsActive            = true,
                };


                db.Gyms.Add(gym);
                var target   = request.address + " " + request.state + " " + request.zip;
                var geocoded = Geocoder.GeoCodeAddress(target);
                if (geocoded != null)
                {
                    gym.Position = System.Data.Entity.Spatial.DbGeography.FromText(geocoded.GetPointString());
                    db.SaveChanges();

                    var newgymBody = "Gym Registration"
                                     + Environment.NewLine
                                     + "Gym Name: "
                                     + gym.GymName
                                     + Environment.NewLine
                                     + "Location: "
                                     + request.address
                                     + Environment.NewLine
                                     + "City: "
                                     + request.city
                                     + Environment.NewLine
                                     + "State: "
                                     + request.state
                                     + Environment.NewLine
                                     + "Zip Code: "
                                     + request.zip
                                     + Environment.NewLine
                                     + "Gym Phone"
                                     + request.gymPhone
                                     + Environment.NewLine
                                     + "Contact Name: "
                                     + request.contactName
                                     + Environment.NewLine
                                     + "Contact Email: "
                                     + request.contactEmail
                                     + Environment.NewLine
                                     + "Contact Phone: "
                                     + request.contactPhone
                                     + Environment.NewLine
                                     + "Website: "
                                     + gym.Url
                                     + Environment.NewLine;

                    SlackHelper.sendGymSignupChannel(newgymBody, geocoded.Latitude.ToString(), geocoded.Longitude.ToString());
                    // add gym id
                    var gymId = gym.GymId;
                    var link  = Constants.PedalWebUrl + "gym.html#/login";

                    EmailTemplateHelper.SendEmail("Welcome to Pedal!", request.contactEmail, link, request.gymName, "gym_signup.html");
                }
                else
                {
                    db.ContactInfoes.Remove(gym.ContactInfo);
                    db.ContactInfoes.Remove(gym.ContactInfo1);

                    var supportText = "Gym Registration - Location not found!"
                                      + Environment.NewLine
                                      + "Gym Name: "
                                      + gym.GymName
                                      + Environment.NewLine
                                      + "Location: "
                                      + request.address
                                      + Environment.NewLine
                                      + "City: "
                                      + request.city
                                      + Environment.NewLine
                                      + "State: "
                                      + request.state
                                      + Environment.NewLine
                                      + "Zip Code: "
                                      + request.zip
                                      + Environment.NewLine
                                      + "Gym Phone"
                                      + request.gymPhone
                                      + Environment.NewLine
                                      + "Contact Name: "
                                      + request.contactName
                                      + Environment.NewLine
                                      + "Contact Email: "
                                      + request.contactEmail
                                      + Environment.NewLine
                                      + "Contact Phone: "
                                      + request.contactPhone
                                      + Environment.NewLine
                                      + "Website: "
                                      + gym.Url
                                      + Environment.NewLine;

                    SlackHelper.sendSupportChannel(supportText);

                    EmailNoTemplateHelper.SendEmail("Gym Registration Problem", "*****@*****.**", supportText);

                    return(new GymDataResponse {
                        success = false, status = 200, message = "Location could not be found. The Pedal team has been notified to look into this."
                    });
                }


                return(gymDataHelper.CreateGymDataResponse(gym.GymId, true));
            }
        }
        public static BasicResponse updateGymInfoImplementation(UpdateGymInfoRequest request)
        {
            if (request == null || String.IsNullOrWhiteSpace(request.authToken) || request.accountId == null)
            {
                return(new BasicResponse
                {
                    message = "Gym not found.",
                    status = 404,
                    success = false,
                });
            }

            if (String.IsNullOrWhiteSpace(request.data.address))
            {
                return(new BasicResponse
                {
                    message = "Please enter an address.",
                    status = 404,
                    success = false,
                });
            }

            if (String.IsNullOrWhiteSpace(request.data.city))
            {
                return(new BasicResponse
                {
                    message = "Please enter a city.",
                    status = 404,
                    success = false,
                });
            }

            if (String.IsNullOrWhiteSpace(request.data.contactName))
            {
                return(new BasicResponse
                {
                    message = "Please enter a contact name.",
                    status = 404,
                    success = false,
                });
            }

            if (String.IsNullOrWhiteSpace(request.data.contactPhone))
            {
                return(new BasicResponse
                {
                    message = "Please enter a contact phone number.",
                    status = 404,
                    success = false,
                });
            }

            if (String.IsNullOrWhiteSpace(request.data.gymName))
            {
                return(new BasicResponse
                {
                    message = "Please enter a gym name.",
                    status = 404,
                    success = false,
                });
            }

            if (String.IsNullOrWhiteSpace(request.data.gymPhone))
            {
                return(new BasicResponse
                {
                    message = "Please enter a gym phone number.",
                    status = 404,
                    success = false,
                });
            }

            if (String.IsNullOrWhiteSpace(request.data.gymUrl))
            {
                return(new BasicResponse
                {
                    message = "Please enter a gym url.",
                    status = 404,
                    success = false,
                });
            }

            if (String.IsNullOrWhiteSpace(request.data.state))
            {
                return(new BasicResponse
                {
                    message = "Please enter a state.",
                    status = 404,
                    success = false,
                });
            }

            if (String.IsNullOrWhiteSpace(request.data.zip))
            {
                return(new BasicResponse
                {
                    message = "Please enter a zip code.",
                    status = 404,
                    success = false,
                });
            }

            using (var db = new UniversalGymEntities())
            {
                var gym = db.Gyms.SingleOrDefault(a => a.CurrentToken == request.authToken && a.GymId == request.accountId);
                if (gym == null)
                {
                    return(new BasicResponse
                    {
                        message = "Gym not found.",
                        status = 404,
                        success = false,
                    });
                }


                var state = db.TypeStates.FirstOrDefault(f => f.StateAbbreviation.ToLower() == request.data.state.ToLower()) ??
                            db.TypeStates.First(f => f.StateAbbreviation == "00");
                gym.ContactInfo1.Address.TypeStateId = state.TypeStateId;
                gym.ContactInfo1.Address.City        = request.data.city;
                gym.ContactInfo1.Address.Zip         = request.data.zip;
                gym.ContactInfo.Phone  = request.data.contactPhone;
                gym.ContactInfo1.Phone = request.data.gymPhone;
                gym.GymName            = request.data.gymName;
                gym.GymInfo            = request.data.description;
                gym.OwnerName          = request.data.contactName;
                var url = request.data.gymUrl;
                if (!String.IsNullOrWhiteSpace(url))
                {
                    gym.Url = new UriBuilder(url).Uri.ToString();
                }
                db.SaveChanges();


                db.SaveChanges();

                var target   = request.data.address + " " + request.data.state + " " + request.data.zip;
                var geocoded = Geocoder.GeoCodeAddress(target);

                if (geocoded != null)
                {
                    gym.Position = System.Data.Entity.Spatial.DbGeography.FromText(geocoded.GetPointString());
                    db.SaveChanges();
                }

                return(new BasicResponse()
                {
                    success = true, status = 200, message = "Success!"
                });
            }
        }