Exemplo n.º 1
0
        public void SendCall(Call call, CallDispatch dispatch, UserProfile profile = null)
        {
            if (Config.SystemBehaviorConfig.DoNotBroadcast)
            {
                return;
            }

            if (profile == null)
            {
                profile = _userProfileService.GetProfileByUserId(dispatch.UserId);
            }

            string emailAddress = String.Empty;

            if (dispatch.User != null && dispatch.User != null)
            {
                emailAddress = dispatch.User.Email;
            }
            else
            {
                //Logging.LogError(string.Format("Send Call Email (Missing User Membership): {0} User: {1}", call.CallId, dispatch.UserId));
                var user = _usersService.GetUserById(dispatch.UserId, false);

                if (user != null && user != null)
                {
                    emailAddress = user.Email;
                }
            }

            string subject  = string.Empty;
            string priority = string.Empty;
            string address  = string.Empty;

            if (call.IsCritical)
            {
                subject  = string.Format("Resgrid CRITICAL Call: P{0} {1}", call.Priority, call.Name);
                priority = string.Format("{0} CRITICAL", ((CallPriority)call.Priority).ToString());
            }
            else
            {
                subject  = string.Format("Resgrid Call: P{0} {1}", call.Priority, call.Name);
                priority = string.Format("{0}", ((CallPriority)call.Priority).ToString());
            }

            string coordinates = "No Coordinates Supplied";

            if (!string.IsNullOrEmpty(call.GeoLocationData))
            {
                coordinates = call.GeoLocationData;

                string[] points = call.GeoLocationData.Split(char.Parse(","));

                if (points != null && points.Length == 2)
                {
                    try
                    {
                        address = _geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(points[0]), double.Parse(points[1]));
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            if (!string.IsNullOrEmpty(call.Address) && string.IsNullOrWhiteSpace(address))
            {
                address = call.Address;
            }
            else
            {
                address = "No Address Supplied";
            }

            string dispatchedOn = String.Empty;

            if (call.Department != null)
            {
                dispatchedOn = call.LoggedOn.FormatForDepartment(call.Department);
            }
            else
            {
                dispatchedOn = call.LoggedOn.ToString("G") + " UTC";
            }



            if (profile != null && profile.SendEmail && !String.IsNullOrWhiteSpace(emailAddress))
            {
                _emailProvider.SendCallMail(emailAddress, subject, call.Name, priority, call.NatureOfCall, call.MapPage,
                                            address, dispatchedOn, call.CallId, dispatch.UserId, coordinates, call.ShortenedAudioUrl);
            }
        }