Beispiel #1
0
        /// <summary>
        /// Converts from the FoundOPS model to the API model
        /// </summary>
        /// <param name="serviceModel">The service to convert</param>
        /// <returns>A Service that has been converted to it's API model</returns>
        public static Service ConvertModel(FoundOps.Core.Models.CoreEntities.Service serviceModel)
        {
            //Create the new service and set its properties
            var service = new Service
            {
                Id = serviceModel.Id,
                CreatedDate = serviceModel.CreatedDate,
                Name = serviceModel.ServiceTemplate.Name,
                ServiceDate = serviceModel.ServiceDate,
                ClientId = serviceModel.ClientId,
                Client = serviceModel.Client != null ? Client.ConvertModel(serviceModel.Client) : null,
                ServiceProviderId = serviceModel.ServiceProviderId,
                RecurringServiceId = serviceModel.RecurringServiceId
            };

            service.SetLastModified(serviceModel.LastModified, serviceModel.LastModifyingUserId);

            if (serviceModel.RecurringServiceParent != null && serviceModel.RecurringServiceParent.Repeat != null)
                service.Repeat = Repeat.ConvertModel(serviceModel.RecurringServiceParent.Repeat);

            //Convert each field from the FoundOPS model to the API model
            //Add the newly converted field to the newly created service
            foreach (var field in serviceModel.ServiceTemplate.Fields.OrderBy(f => f.Name))
                service.Fields.Add(Field.ConvertModel(field));

            service.ParentServiceTemplateId = serviceModel.ServiceTemplate.OwnerServiceTemplateId;

            return service;
        }
Beispiel #2
0
        public static ContactInfo Convert(FoundOps.Core.Models.CoreEntities.ContactInfo contactInfoModel)
        {
            var contactInfo = new ContactInfo
                {
                    Id = contactInfoModel.Id,
                    CreatedDate = contactInfoModel.CreatedDate,
                    Type = contactInfoModel.Type,
                    Label = contactInfoModel.Label,
                    Data = contactInfoModel.Data,
                    ClientId = contactInfoModel.ClientId,
                    LocationId = contactInfoModel.LocationId
                };

            contactInfo.SetLastModified(contactInfoModel.LastModified, contactInfoModel.LastModifyingUserId);

            //TODO Generalize this everywhere
            if (string.IsNullOrEmpty(contactInfo.Type))
                contactInfo.Type = "";
            if (string.IsNullOrEmpty(contactInfo.Label))
                contactInfo.Label = "";
            if (string.IsNullOrEmpty(contactInfo.Data))
                contactInfo.Data = "";

            return contactInfo;
        }
Beispiel #3
0
        /// <summary>
        /// Converts from the FoundOPS model to the API model
        /// </summary>
        public static ServiceTemplate ConvertModel(FoundOps.Core.Models.CoreEntities.ServiceTemplate model)
        {
            var serviceType = new ServiceTemplate
            {
                Id = model.Id,
                Name = model.Name
            };

            return serviceType;
        }
Beispiel #4
0
        public static Repeat ConvertModel(FoundOps.Core.Models.CoreEntities.Repeat repeatModel)
        {
            var repeat = new Api.Models.Repeat
            {
                Id = repeatModel.Id,
                StartDate = repeatModel.StartDate,
                EndDate = repeatModel.EndDate,
                EndAfterTimes = repeatModel.EndAfterTimes,
                RepeatEveryTimes = repeatModel.RepeatEveryTimes,
                FrequencyInt = repeatModel.FrequencyInt,
                FrequencyDetailInt = repeatModel.FrequencyDetailInt
            };

            return repeat;
        }
Beispiel #5
0
        public static Client ConvertModel(FoundOps.Core.Models.CoreEntities.Client clientModel)
        {
            var client = new Client
            {
                Id = clientModel.Id,
                CreatedDate = clientModel.CreatedDate,
                Name = clientModel.Name
            };

            client.SetLastModified(clientModel.LastModified, clientModel.LastModifyingUserId);

            foreach (var contactInfo in clientModel.ContactInfoSet)
                client.ContactInfoSet.Add(ContactInfo.Convert(contactInfo));

            return client;
        }
Beispiel #6
0
        /// <summary>
        /// Converts the model.
        /// </summary>
        /// <param name="routeModel">The route model.</param>
        /// <returns>The corresponding API model for Route.</returns>
        public static Route ConvertModel(FoundOps.Core.Models.CoreEntities.Route routeModel)
        {
            var route = new Route
                {
                    Id = routeModel.Id,
                    CreatedDate = routeModel.CreatedDate,
                    Name = routeModel.Name,
                    BusinessAccountId = routeModel.OwnerBusinessAccountId
                };

            route.SetLastModified(routeModel.LastModified, routeModel.LastModifyingUserId);

            foreach (var routeDestinationModel in routeModel.RouteDestinations.OrderBy(rd => rd.OrderInRoute))
                route.RouteDestinations.Add(RouteDestination.ConvertModel(routeDestinationModel));

            return route;
        }
Beispiel #7
0
        public static TaskStatus ConvertModel(FoundOps.Core.Models.CoreEntities.TaskStatus model)
        {
            var status = new TaskStatus
            {
                Id = model.Id,
                CreatedDate = model.CreatedDate,
                Name = model.Name,
                Color = model.Color,
                DefaultTypeInt = model.DefaultTypeInt,
                RemoveFromRoute = model.RemoveFromRoute,
                BusinessAccountId = model.BusinessAccountId
            };

            status.SetLastModified(model.LastModified, model.LastModifyingUserId);

            return status;
        }
Beispiel #8
0
        public static RouteTask ConvertModel(FoundOps.Core.Models.CoreEntities.RouteTask routeTaskModel)
        {
            var routeTask = new RouteTask
                {
                    Id = routeTaskModel.Id, 
                    CreatedDate = routeTaskModel.CreatedDate,
                    Name = routeTaskModel.Name, 
                    Date = routeTaskModel.Date, 
                    RecurringServiceId = routeTaskModel.RecurringServiceId, 
                    ServiceId = routeTaskModel.ServiceId, 
                    TaskStatusId = routeTaskModel.TaskStatusId
                };

            routeTask.SetLastModified(routeTaskModel.LastModified, routeTaskModel.LastModifyingUserId);

            return routeTask;
        }
Beispiel #9
0
        public static RouteDestination ConvertModel(FoundOps.Core.Models.CoreEntities.RouteDestination routeDestinationModel)
        {
            var routeDestination = new RouteDestination
                {
                    Id = routeDestinationModel.Id, 
                    CreatedDate = routeDestinationModel.CreatedDate,
                    OrderInRoute = routeDestinationModel.OrderInRoute
                };

            routeDestination.SetLastModified(routeDestinationModel.LastModified, routeDestinationModel.LastModifyingUserId);

            foreach (var routeTaskModel in routeDestinationModel.RouteTasks.OrderBy(rt => rt.Name))
                routeDestination.RouteTasks.Add(RouteTask.ConvertModel(routeTaskModel));

            if (routeDestinationModel.Client != null)
                routeDestination.Client = Client.ConvertModel(routeDestinationModel.Client);

            if (routeDestinationModel.Location != null)
                routeDestination.Location = Location.ConvertModel(routeDestinationModel.Location);

            return routeDestination;
        }
Beispiel #10
0
        public static Location ConvertGeocode(FoundOps.Common.NET.GeocoderResult geocoderResult)
        {
            Decimal tempLatLong = 0;

            Decimal.TryParse(geocoderResult.Latitude, out tempLatLong);
            var latitude = tempLatLong == 0 ? (decimal?)null : tempLatLong;

            Decimal.TryParse(geocoderResult.Longitude, out tempLatLong);
            var longitude = tempLatLong == 0 ? (decimal?)null : tempLatLong;

            var location = new Location
            {
                Id = Guid.NewGuid(),
                AddressLineOne = geocoderResult.AddressLineOne,
                AddressLineTwo = geocoderResult.AddressLineTwo,
                AdminDistrictTwo = geocoderResult.City,
                AdminDistrictOne = geocoderResult.State,
                CountryCode = geocoderResult.CountryCode,
                PostalCode = geocoderResult.ZipCode,
                Latitude = latitude != null ? Decimal.Round((decimal) latitude, 8).ToString() : String.Empty,
                Longitude = longitude != null ? Decimal.Round((decimal) longitude, 8).ToString() : String.Empty,
                IsNew = true
            };

            if (location.CountryCode == "United States")
                location.CountryCode = "US";

            return location;
        }
Beispiel #11
0
        private void SetupControl(FoundOps.Core.Models.CoreEntities.Repeat schedule)
        {
            var monthlyFrequencyDetailsStackPanel = new StackPanel();

            if (schedule == null || schedule.AvailableMonthlyFrequencyDetailTypes == null)
            {
                this.Content = null;
                this.InvalidateArrange();
                return;
            }

            foreach (var monthlyFrequencyDetail in schedule.AvailableMonthlyFrequencyDetailTypes)
            {
                var monthlyFrequencyDetailRadioButton = new RadioButton { GroupName = "RepeatOn" };

                monthlyFrequencyDetailRadioButton.SetBinding(ContentControl.ContentProperty,
                                                             new Binding("StartDate")
                                                                 {
                                                                     Source = schedule,
                                                                     Converter =
                                                                         new MonthlyFrequencyDetailToStringConverter(
                                                                         monthlyFrequencyDetail)
                                                                 });

                monthlyFrequencyDetailRadioButton.SetBinding(ToggleButton.IsCheckedProperty,
                                                             new Binding("FrequencyDetailAsMonthlyFrequencyDetail")
                                                                 {
                                                                     Source = schedule,
                                                                     Converter =
                                                                         new MonthlyFrequencyDetailIsCheckedConverter(
                                                                         monthlyFrequencyDetail)
                                                                 });

                var detail = monthlyFrequencyDetail;
                monthlyFrequencyDetailRadioButton.Checked += (o, args) =>
                                                                 {
                                                                     Value.FrequencyDetailAsMonthlyFrequencyDetail = detail;
                                                                 };

                monthlyFrequencyDetailsStackPanel.Children.Add(monthlyFrequencyDetailRadioButton);
            }

            this.Content = monthlyFrequencyDetailsStackPanel;
            this.InvalidateArrange();
        }