Пример #1
0
        private string GetGeoLocationAddress(SageLocation sageLocation)
        {
            var sb = new StringBuilder();

            if (!string.IsNullOrEmpty(sageLocation.Address))
            {
                sb.AppendFormat("{0} ", sageLocation.Address);
            }
            if (!string.IsNullOrEmpty(sageLocation.Address2) && string.IsNullOrEmpty(sageLocation.Address))
            {
                sb.AppendFormat("{0} ", sageLocation.Address2);
            }

            sb.AppendFormat("{0} ", sageLocation.City);
            sb.AppendFormat("{0} ", sageLocation.ZIP);
            sb.AppendFormat("{0} ", sageLocation.State);

            return(sb.ToString().TrimEnd(' '));
        }
Пример #2
0
        public void ResolveLocation(SageLocation sageLocation, SageLocationCache cache = null)
        {
            //var sageLocationCache = new SageLocationCache();
            Thread.Sleep(1000);
            var parametersSearch = GetGeoLocationAddress(sageLocation);
            var location         = GetLocation(parametersSearch);

            if (location?.result != null && location.result.Any())
            {
                var geometry = location.result.First().geometry;
                if (geometry?.location != null)
                {
                    sageLocation.Latitude  = geometry.location.lat;
                    sageLocation.Longitude = geometry.location.lng;

                    var sageLocationCache = cache ?? _repository.SearchFor <SageLocationCache>(x => x.Location == sageLocation.Location)
                                            .SingleOrDefault();


                    if (sageLocationCache != null)
                    {
                        sageLocationCache.Latitude     = geometry.location.lat;
                        sageLocationCache.Longitude    = geometry.location.lng;
                        sageLocationCache.Location     = sageLocation.Location;
                        sageLocationCache.Address      = sageLocation.Address;
                        sageLocationCache.ResolvedDate = DateTime.UtcNow;
                        _repository.Update(sageLocationCache);
                    }
                    else
                    {
                        _repository.Add(new SageLocationCache
                        {
                            Latitude     = geometry.location.lat,
                            Longitude    = geometry.location.lng,
                            Location     = sageLocation.Location,
                            Address      = sageLocation.Address,
                            ResolvedDate = DateTime.UtcNow
                        });
                    }
                }
            }
        }
Пример #3
0
        public bool CerateAssignment(AssignmentViewModel model)
        {
            _log.InfoFormat("Method: CreateAssignment. Model ID {0}", model.Id);
            var databaseAssignment = _repository.SearchFor <SageAssignment>(x => x.WorkOrder == model.WorkOrder).Single();

            var employee = _repository.SearchFor <SageEmployee>(x => x.Employee == model.Employee).SingleOrDefault();

            databaseAssignment.Employee             = employee?.Name ?? "";
            databaseAssignment.ScheduleDate         = model.ScheduleDate;
            databaseAssignment.WorkOrder            = model.WorkOrder;
            databaseAssignment.EstimatedRepairHours = model.EstimatedRepairHours;
            databaseAssignment.StartTime            = model.ScheduleDate;
            databaseAssignment.Enddate = model.EndDate;
            databaseAssignment.Endtime = model.EndDate;

            var edited = _sageApiProxy.EditAssignment(databaseAssignment);

            if (edited.IsSucceed == false)
            {
                _log.ErrorFormat("edited == null. Error.");
                return(false);
            }

            databaseAssignment.EmployeeId = employee != null ? employee.Employee : 0;
            databaseAssignment.Start      = ((DateTime)edited.Entity.ScheduleDate).Add(((DateTime)edited.Entity.StartTime).TimeOfDay).ToString();
            databaseAssignment.End        = ((DateTime)edited.Entity.ScheduleDate).Add(((DateTime)edited.Entity.StartTime).TimeOfDay).AddHours(edited.Entity.EstimatedRepairHours.AsDouble()).ToString();
            databaseAssignment.Color      = employee?.Color ?? "";

            var workorder = _repository.SearchFor <SageWorkOrder>(w => w.WorkOrder == model.WorkOrder).SingleOrDefault();

            databaseAssignment.Customer = workorder.ARCustomer;
            databaseAssignment.Location = workorder.Location;
            var locations    = _repository.GetAll <SageLocation>().ToArray();
            var itemLocation = locations.FirstOrDefault(l => l.Name == workorder.Location);

            if (itemLocation == null)
            {
                itemLocation = new SageLocation();
                _locationService.ResolveLocation(itemLocation);
            }
            else if (itemLocation.Longitude == 0 || itemLocation.Longitude == 0)
            {
                _locationService.ResolveLocation(itemLocation);
            }
            workorder.ScheduleDate = databaseAssignment.ScheduleDate;
            workorder.Latitude     = itemLocation.Latitude;
            workorder.Longitude    = itemLocation.Longitude;
            workorder.Color        = databaseAssignment.Color;
            workorder.EmployeeId   = databaseAssignment.EmployeeId;
            workorder.Employee     = databaseAssignment.Employee;

            _repository.Update(databaseAssignment);
            workorder.AssignmentId = 0;
            _repository.Update(workorder);
            _repository.Update(itemLocation);


            _hub.CreateAssignment(new MapViewModel()
            {
                WorkOrder   = workorder,
                DateEntered = databaseAssignment.ScheduleDate,
                Employee    = employee?.Employee ?? 0,
                Color       = employee?.Color ?? ""
            });

            _notification.SendNotification(string.Format("Workorder {0} assigned to {1}", workorder.Name, employee.Name));
            _log.InfoFormat("DatabaseAssignment added to repository. Employee {0}, Employee ID {1}", databaseAssignment.Employee, databaseAssignment.EmployeeId);

            return(true);
        }