/// <summary>
        /// Validates the specified location field.
        /// </summary>
        /// <param name="value">The Location field's value</param>
        /// <returns></returns>

        public ValidationResult Validate(Location value)
        {
            if (value != null)
                return ValidationResult.Success;

            return new ValidationResult("The location is required.");
        }
        /// <summary>
        /// Deletes the location.
        /// </summary>
        /// <param name="location">The location.</param>
        public void DeleteLocation(Location location)
        {
            var date = this.ObjectContext.CurrentUserAccount().Now();

            ObjectContext.ArchiveLocationBasedOnId(location.Id, date.Date, CurrentUserAccount().Id);
        }
        public void UpdateLocation(Location currentLocation)
        {
            currentLocation.LastModified = DateTime.UtcNow;
            currentLocation.LastModifyingUserId = CurrentUserAccount().Id;

            this.ObjectContext.Locations.AttachAsModified(currentLocation);
        }
 public void InsertLocation(Location location)
 {
     if ((location.EntityState != EntityState.Detached))
     {
         this.ObjectContext.ObjectStateManager.ChangeObjectState(location, EntityState.Added);
     }
     else
     {
         this.ObjectContext.Locations.AddObject(location);
     }
 }
Beispiel #5
0
        public LocationVM(Location entity)
        {
            #region Register Commands

            SearchCommand = new RelayCommand(OnSearch);
            SetLocationToGeocoderResultCommand = new RelayCommand(OnSetLocation,
                                                                  () =>
                                                                  SelectedGeocoderResult != null &&
                                                                  !String.IsNullOrEmpty(SelectedGeocoderResult.Latitude) &&
                                                                  !String.IsNullOrEmpty(SelectedGeocoderResult.Longitude));
            ManuallySetLatitudeLongitude = new RelayCommand<Tuple<decimal, decimal>>(OnManuallySetLatitudeLongitude,
                                                                                     (latitudeLongitude) =>
                                                                                     SelectedGeocoderResult != null &&
                                                                                     SelectedGeocoderResult.Name ==
                                                                                     ManuallySelectLocationString);

            #endregion

            #region Entity logic

            _entity = entity;

            //Setup the ContactInfoVM
            ContactInfoVM = new ContactInfoVM(ContactInfoType.Locations, entity != null ? entity.ContactInfoSet : null);

            ManuallySelectGeocoderResult = new GeocoderResult { Name = ManuallySelectLocationString, AddressLineOne = ClickOnTheMapString };

            var depot = ContextManager.ServiceProvider.Depots.FirstOrDefault();
            var ipInformation = ((string)Application.Current.Resources["IPInformation"]);

            //Set ManuallySelectGeocoderResult to the Entity if it has a Latitude/Longitude
            if (entity != null && entity.Latitude != null && entity.Longitude != null)
            {
                ManuallySelectGeocoderResult.Latitude = entity.Latitude.Value.ToString();
                ManuallySelectGeocoderResult.Longitude = entity.Longitude.Value.ToString();
                SelectedGeocoderResult = ManuallySelectGeocoderResult;
                if (SelectedGeocoderResult.TelerikLocation != null)
                    MessageBus.Current.SendMessage(new LocationSetMessage(SelectedGeocoderResult.TelerikLocation.Value));
            }
            //Otherwise set it to the depot if there is one
            else if (depot != null && depot.Latitude.HasValue && depot.Longitude.HasValue)
            {
                ManuallySelectGeocoderResult.Latitude = depot.Latitude.Value.ToString();
                ManuallySelectGeocoderResult.Longitude = depot.Longitude.Value.ToString();
            }
            //Otherwise use the IPInfo if there is any
            else if (ipInformation != null)
            {
                var ipInformationDelimited = ipInformation.Split(';');
                var latitude = ipInformationDelimited[8];
                var longitude = ipInformationDelimited[9];

                ManuallySelectGeocoderResult.Latitude = latitude;
                ManuallySelectGeocoderResult.Longitude = longitude;
            }

            #endregion

            if (entity == null)
                return;

            //Set the default SearchText
            SearchText = string.Format("{0}, {1}, {2}, {3}", entity.AddressLineOne, entity.AdminDistrictTwo, entity.AdminDistrictOne, entity.PostalCode);

            #region Subscribe to Location state validation
            //Setup ValidLatitudeLongitude observable, it will be valid as long as the Entity's lat & long have a value
            //Start with a value
            ValidLatitudeLongitudeState = new BehaviorSubject<bool>(Entity.Latitude.HasValue && Entity.Longitude.HasValue);
            // Subscribe to changes
            Observable2.FromPropertyChangedPattern(Entity, x => x.Latitude).CombineLatest(
                Observable2.FromPropertyChangedPattern(Entity, x => x.Longitude), (a, b) => a.HasValue && b.HasValue).Throttle(new TimeSpan(0, 0, 0, 0, 250))
                .Subscribe((BehaviorSubject<bool>)ValidLatitudeLongitudeState);

            #endregion
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Locations EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToLocations(Location location)
 {
     base.AddObject("Locations", location);
 }
 /// <summary>
 /// Create a new Location object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 public static Location CreateLocation(global::System.Guid id, global::System.DateTime createdDate)
 {
     Location location = new Location();
     location.Id = id;
     location.CreatedDate = createdDate;
     return location;
 }
        /// <summary>
        /// Serves three functions. 
        /// 1) Convert the FoundOPS location to the API model.
        /// 2) Set the Region on the location if it exists.
        /// 3) Set the Status of the Location.
        /// </summary>
        /// <param name="matchedLocation">Location to be converted</param>
        /// <param name="regionName">The name of the region the be added to the Locations</param>
        /// <param name="status">The status to be assigned to the Location</param>
        /// <returns>An API location to be imported</returns>
        private Models.Location ConvertLocationSetRegionAndStatus(Location matchedLocation, string regionName, ImportStatus status)
        {
            var location = Api.Models.Location.ConvertModel(matchedLocation);

            location.Region = SetRegion(regionName);

            location.StatusInt = (int)status;

            return location;
        }