Exemplo n.º 1
0
        public HttpResponseMessage CloseCall([FromBody] CloseCallInput closeCallInput)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            var call = _callsService.GetCallById(closeCallInput.Id);

            if (call == null)
            {
                throw HttpStatusCode.NotFound.AsException();
            }

            call.ClosedByUserId = UserId;
            call.ClosedOn       = DateTime.UtcNow;
            call.CompletedNotes = closeCallInput.Msg;
            call.State          = (int)closeCallInput.Typ;

            _callsService.SaveCall(call);

            OutboundEventProvider.CallAddedTopicHandler handler = new OutboundEventProvider.CallAddedTopicHandler();
            handler.Handle(new CallAddedEvent()
            {
                DepartmentId = DepartmentId, Call = call
            });

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Exemplo n.º 2
0
        public HttpResponseMessage EditCall([FromBody] EditCallInput editCallInput)
        {
            var call = _callsService.GetCallById(editCallInput.Cid);

            if (call == null)
            {
                throw HttpStatusCode.NotFound.AsException();
            }

            if (call.DepartmentId != DepartmentId)
            {
                throw HttpStatusCode.Unauthorized.AsException();
            }

            if (call.State != (int)CallStates.Active)
            {
                throw HttpStatusCode.NotAcceptable.AsException();
            }

            if (!String.IsNullOrWhiteSpace(editCallInput.Nme) && editCallInput.Nme != call.Name)
            {
                call.Name = editCallInput.Nme;
            }

            if (!String.IsNullOrWhiteSpace(editCallInput.Noc) && editCallInput.Noc != call.NatureOfCall)
            {
                call.NatureOfCall = editCallInput.Noc;
            }

            if (!String.IsNullOrWhiteSpace(editCallInput.Add) && editCallInput.Add != call.Address)
            {
                call.Address = editCallInput.Add;
            }

            _callsService.SaveCall(call);

            OutboundEventProvider.CallAddedTopicHandler handler = new OutboundEventProvider.CallAddedTopicHandler();
            handler.Handle(new CallAddedEvent()
            {
                DepartmentId = DepartmentId, Call = call
            });

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a new call into Resgrid and Dispatches the call
        /// </summary>
        /// <param name="callInput">Call data to add into the system</param>
        /// <returns></returns>
        public async Task <AddCallInput> AddCall([FromBody] AddCallInput callInput)
        {
            try
            {
                var call = new Call
                {
                    DepartmentId     = DepartmentId,
                    ReportingUserId  = UserId,
                    Priority         = callInput.Priority,
                    Name             = callInput.Name,
                    NatureOfCall     = callInput.NatureOfCall,
                    Number           = callInput.Number,
                    IsCritical       = callInput.IsCritical,
                    IncidentNumber   = callInput.IncidentNumber,
                    MapPage          = callInput.MapPage,
                    Notes            = callInput.Notes,
                    CompletedNotes   = callInput.CompletedNotes,
                    Address          = callInput.Address,
                    GeoLocationData  = callInput.GeoLocationData,
                    LoggedOn         = callInput.LoggedOn,
                    ClosedByUserId   = callInput.ClosedByUserId,
                    ClosedOn         = callInput.ClosedOn,
                    State            = callInput.State,
                    IsDeleted        = callInput.IsDeleted,
                    CallSource       = callInput.CallSource,
                    DispatchCount    = callInput.DispatchCount,
                    LastDispatchedOn = callInput.LastDispatchedOn,
                    SourceIdentifier = callInput.SourceIdentifier,
                    W3W                = callInput.W3W,
                    ContactName        = callInput.ContactName,
                    ContactNumber      = callInput.ContactNumber,
                    Public             = callInput.Public,
                    ExternalIdentifier = callInput.ExternalIdentifier,
                    ReferenceNumber    = callInput.ReferenceNumber
                };

                if (string.IsNullOrWhiteSpace(call.GeoLocationData) && !string.IsNullOrWhiteSpace(call.Address))
                {
                    call.GeoLocationData = _geoLocationProvider.GetLatLonFromAddress(call.Address);
                }

                if (string.IsNullOrWhiteSpace(call.GeoLocationData) && !string.IsNullOrWhiteSpace(call.W3W))
                {
                    var coords = await _geoLocationProvider.GetCoordinatesFromW3WAsync(call.W3W);

                    if (coords != null)
                    {
                        call.GeoLocationData = $"{coords.Latitude},{coords.Longitude}";
                    }
                }

                call.LoggedOn = DateTime.UtcNow;

                if (!String.IsNullOrWhiteSpace(callInput.Type) && callInput.Type != "No Type")
                {
                    var callTypes = await _callsService.GetCallTypesForDepartmentAsync(DepartmentId);

                    var type = callTypes.FirstOrDefault(x => x.Type == callInput.Type);

                    if (type != null)
                    {
                        call.Type = type.Type;
                    }
                }

                call.Dispatches      = new List <CallDispatch>();
                call.GroupDispatches = new List <CallDispatchGroup>();
                call.RoleDispatches  = new List <CallDispatchRole>();

                List <string> groupUserIds = new List <string>();

                var users = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId);

                if (callInput.AllCall)
                {
                    foreach (var u in users)
                    {
                        var cd = new CallDispatch {
                            UserId = u.UserId
                        };

                        call.Dispatches.Add(cd);
                    }
                }
                else
                {
                    if (callInput.GroupCodesToDispatch != null && callInput.GroupCodesToDispatch.Count > 0)
                    {
                        var allGroups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

                        foreach (var groupCode in callInput.GroupCodesToDispatch)
                        {
                            var groupsToDispatch = allGroups.FirstOrDefault(x => x.DispatchEmail == groupCode);

                            if (groupsToDispatch != null)
                            {
                                var cd = new CallDispatchGroup {
                                    DepartmentGroupId = groupsToDispatch.DepartmentGroupId
                                };
                                call.GroupDispatches.Add(cd);

                                if (groupsToDispatch.Members != null && groupsToDispatch.Members.Any())
                                {
                                    foreach (var departmentGroupMember in groupsToDispatch.Members)
                                    {
                                        if (!groupUserIds.Contains(departmentGroupMember.UserId))
                                        {
                                            groupUserIds.Add(departmentGroupMember.UserId);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (callInput.Attachments != null && callInput.Attachments.Any())
                {
                    call.Attachments = new List <CallAttachment>();

                    foreach (var attachment in callInput.Attachments)
                    {
                        var newAttachment = new CallAttachment();
                        newAttachment.Data               = attachment.Data;
                        newAttachment.Timestamp          = DateTime.UtcNow;
                        newAttachment.FileName           = attachment.FileName;
                        newAttachment.Size               = attachment.Size;
                        newAttachment.CallAttachmentType = attachment.CallAttachmentType;

                        call.Attachments.Add(newAttachment);
                    }
                }

                var savedCall = _callsService.SaveCall(call);


                OutboundEventProvider.CallAddedTopicHandler handler = new OutboundEventProvider.CallAddedTopicHandler();
                handler.Handle(new CallAddedEvent()
                {
                    DepartmentId = DepartmentId, Call = savedCall
                });

                var cqi = new CallQueueItem();
                cqi.Call = savedCall;

                if (cqi.Call.Dispatches != null && cqi.Call.Dispatches.Any())
                {
                    cqi.Profiles =
                        await _userProfileService.GetSelectedUserProfilesAsync(cqi.Call.Dispatches.Select(x => x.UserId).ToList());
                }
                else
                {
                    if (groupUserIds.Any())
                    {
                        cqi.Profiles = await _userProfileService.GetSelectedUserProfilesAsync(groupUserIds);
                    }
                }

                _queueService.EnqueueCallBroadcast(cqi);

                callInput.CallId = savedCall.CallId;
                callInput.Number = savedCall.Number;
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);

                throw ex;
            }

            return(callInput);
        }
Exemplo n.º 4
0
        public HttpResponseMessage SaveCall([FromBody] NewCallInput newCallInput)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            var call = new Call
            {
                DepartmentId    = DepartmentId,
                ReportingUserId = UserId,
                Priority        = (int)Enum.Parse(typeof(CallPriority), newCallInput.Pri),
                Name            = newCallInput.Nme,
                NatureOfCall    = newCallInput.Noc
            };

            if (!string.IsNullOrWhiteSpace(newCallInput.CNme))
            {
                call.ContactName = newCallInput.CNme;
            }

            if (!string.IsNullOrWhiteSpace(newCallInput.CNum))
            {
                call.ContactName = newCallInput.CNum;
            }

            if (!string.IsNullOrWhiteSpace(newCallInput.Cid))
            {
                call.IncidentNumber = newCallInput.Cid;
            }

            if (!string.IsNullOrWhiteSpace(newCallInput.Add))
            {
                call.Address = newCallInput.Add;
            }

            if (!string.IsNullOrWhiteSpace(newCallInput.W3W))
            {
                call.W3W = newCallInput.W3W;
            }

            //if (call.Address.Equals("Current Coordinates", StringComparison.InvariantCultureIgnoreCase))
            //	call.Address = "";

            if (!string.IsNullOrWhiteSpace(newCallInput.Not))
            {
                call.Notes = newCallInput.Not;
            }

            if (!string.IsNullOrWhiteSpace(newCallInput.Geo))
            {
                call.GeoLocationData = newCallInput.Geo;
            }

            if (string.IsNullOrWhiteSpace(call.GeoLocationData) && !string.IsNullOrWhiteSpace(call.Address))
            {
                call.GeoLocationData = _geoLocationProvider.GetLatLonFromAddress(call.Address);
            }

            if (string.IsNullOrWhiteSpace(call.GeoLocationData) && !string.IsNullOrWhiteSpace(call.W3W))
            {
                var coords = _geoLocationProvider.GetCoordinatesFromW3W(call.W3W);

                if (coords != null)
                {
                    call.GeoLocationData = $"{coords.Latitude},{coords.Longitude}";
                }
            }

            call.LoggedOn = DateTime.UtcNow;

            if (!String.IsNullOrWhiteSpace(newCallInput.Typ) && newCallInput.Typ != "No Type")
            {
                var callTypes = _callsService.GetCallTypesForDepartment(DepartmentId);
                var type      = callTypes.FirstOrDefault(x => x.Type == newCallInput.Typ);

                if (type != null)
                {
                    call.Type = type.Type;
                }
            }
            var users = _departmentsService.GetAllUsersForDepartment(DepartmentId);

            call.Dispatches      = new Collection <CallDispatch>();
            call.GroupDispatches = new List <CallDispatchGroup>();
            call.RoleDispatches  = new List <CallDispatchRole>();

            if (string.IsNullOrWhiteSpace(newCallInput.Dis) || newCallInput.Dis == "0")
            {
                // Use case, existing clients and non-ionic2 app this will be null dispatch all users. Or we've specified everyone (0).
                foreach (var u in users)
                {
                    var cd = new CallDispatch {
                        UserId = u.UserId
                    };

                    call.Dispatches.Add(cd);
                }
            }
            else
            {
                var dispatch = newCallInput.Dis.Split(char.Parse("|"));

                try
                {
                    var usersToDispatch = dispatch.Where(x => x.StartsWith("P:")).Select(y => y.Replace("P:", ""));
                    foreach (var user in usersToDispatch)
                    {
                        var cd = new CallDispatch {
                            UserId = user
                        };
                        call.Dispatches.Add(cd);
                    }
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                }

                try
                {
                    var groupsToDispatch = dispatch.Where(x => x.StartsWith("G:")).Select(y => int.Parse(y.Replace("G:", "")));
                    foreach (var group in groupsToDispatch)
                    {
                        var cd = new CallDispatchGroup {
                            DepartmentGroupId = group
                        };
                        call.GroupDispatches.Add(cd);
                    }
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                }

                try
                {
                    var rolesToDispatch = dispatch.Where(x => x.StartsWith("R:")).Select(y => int.Parse(y.Replace("R:", "")));
                    foreach (var role in rolesToDispatch)
                    {
                        var cd = new CallDispatchRole {
                            RoleId = role
                        };
                        call.RoleDispatches.Add(cd);
                    }
                }
                catch (Exception ex)
                {
                    Logging.LogException(ex);
                }
            }


            var savedCall = _callsService.SaveCall(call);

            OutboundEventProvider.CallAddedTopicHandler handler = new OutboundEventProvider.CallAddedTopicHandler();
            handler.Handle(new CallAddedEvent()
            {
                DepartmentId = DepartmentId, Call = savedCall
            });

            var profiles = new List <string>();

            if (call.Dispatches != null && call.Dispatches.Any())
            {
                profiles.AddRange(call.Dispatches.Select(x => x.UserId).ToList());
            }

            if (call.GroupDispatches != null && call.GroupDispatches.Any())
            {
                foreach (var groupDispatch in call.GroupDispatches)
                {
                    var group = _departmentGroupsService.GetGroupById(groupDispatch.DepartmentGroupId);

                    if (group != null && group.Members != null)
                    {
                        profiles.AddRange(group.Members.Select(x => x.UserId));
                    }
                }
            }

            if (call.RoleDispatches != null && call.RoleDispatches.Any())
            {
                foreach (var roleDispatch in call.RoleDispatches)
                {
                    var members = _personnelRolesService.GetAllMembersOfRole(roleDispatch.RoleId);

                    if (members != null)
                    {
                        profiles.AddRange(members.Select(x => x.UserId).ToList());
                    }
                }
            }

            var cqi = new CallQueueItem();

            cqi.Call     = savedCall;
            cqi.Profiles = _userProfileService.GetSelectedUserProfiles(profiles);

            _queueService.EnqueueCallBroadcast(cqi);

            return(Request.CreateResponse(HttpStatusCode.Created));
        }