Exemplo n.º 1
0
        private Call CreateNewCallFromCall(Call call)
        {
            Call newCall = new Call();

            newCall.Number           = call.Number;
            newCall.DepartmentId     = call.DepartmentId;
            newCall.ReportingUserId  = call.ReportingUserId;
            newCall.Priority         = call.Priority;
            newCall.IsCritical       = call.IsCritical;
            newCall.Type             = call.Type;
            newCall.IncidentNumber   = call.IncidentNumber;
            newCall.Name             = call.Name;
            newCall.NatureOfCall     = call.NatureOfCall;
            newCall.MapPage          = call.MapPage;
            newCall.Notes            = call.Notes;
            newCall.CompletedNotes   = call.CompletedNotes;
            newCall.Address          = call.Address;
            newCall.GeoLocationData  = call.GeoLocationData;
            newCall.LoggedOn         = call.LoggedOn;
            newCall.ClosedByUserId   = call.ClosedByUserId;
            newCall.ClosedOn         = call.ClosedOn;
            newCall.State            = call.State;
            newCall.IsDeleted        = call.IsDeleted;
            newCall.CallSource       = call.CallSource;
            newCall.SourceIdentifier = call.SourceIdentifier;
            newCall.State            = call.State;

            if (call.Dispatches != null && call.Dispatches.Any())
            {
                newCall.Dispatches = new List <CallDispatch>();

                foreach (var callDispatch in call.Dispatches)
                {
                    var cd = new CallDispatch();
                    cd.UserId = callDispatch.UserId;

                    newCall.Dispatches.Add(cd);
                }
            }

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

                foreach (var callAttahment in call.Attachments)
                {
                    var ca = new CallAttachment();
                    ca.CallAttachmentType = callAttahment.CallAttachmentType;
                    ca.Data     = callAttahment.Data;
                    ca.FileName = callAttahment.FileName;

                    newCall.Attachments.Add(ca);
                }
            }

            return(newCall);
        }
Exemplo n.º 2
0
        public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority)
        {
            if (email == null)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(email.Body))
            {
                return(null);
            }

            if (String.IsNullOrEmpty(email.Subject))
            {
                return(null);
            }

            if (!email.Subject.ToLower().Contains("page"))
            {
                return(null);
            }

            Call c = new Call();

            c.Notes            = email.Subject + " " + email.Body;
            c.NatureOfCall     = email.Subject + " " + email.Body;
            c.Name             = email.Subject;
            c.LoggedOn         = DateTime.UtcNow;
            c.Priority         = priority;
            c.ReportingUserId  = managingUser;
            c.Dispatches       = new Collection <CallDispatch>();
            c.CallSource       = (int)CallSources.EmailImport;
            c.SourceIdentifier = email.MessageId;

            if (email.DispatchAudio != null)
            {
                c.Attachments = new Collection <CallAttachment>();

                CallAttachment ca = new CallAttachment();
                ca.FileName           = email.DispatchAudioFileName;
                ca.Data               = email.DispatchAudio;
                ca.CallAttachmentType = (int)CallAttachmentTypes.DispatchAudio;

                c.Attachments.Add(ca);
            }

            foreach (var u in users)
            {
                CallDispatch cd = new CallDispatch();
                cd.UserId = u.UserId;

                c.Dispatches.Add(cd);
            }

            return(c);
        }
Exemplo n.º 3
0
        public HttpResponseMessage UploadFile(CallFileInput input)
        {
            var result = new HttpResponseMessage(HttpStatusCode.OK);

            var call = _callsService.GetCallById(input.Cid);

            if (call == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            if (call.DepartmentId != DepartmentId)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            if (call.State != (int)CallStates.Active)
            {
                return(Request.CreateResponse(HttpStatusCode.NotAcceptable));
            }

            var callAttachment = new CallAttachment();

            callAttachment.CallId             = input.Cid;
            callAttachment.CallAttachmentType = input.Typ;

            if (String.IsNullOrWhiteSpace(input.Nme))
            {
                callAttachment.FileName = "cameraPhoneUpload.png";
            }
            else
            {
                callAttachment.FileName = input.Nme;
            }

            callAttachment.UserId    = input.Uid;
            callAttachment.Timestamp = DateTime.UtcNow;
            callAttachment.Data      = Convert.FromBase64String(input.Data);

            if (!String.IsNullOrWhiteSpace(input.Lat))
            {
                callAttachment.Latitude = decimal.Parse(input.Lat);
            }

            if (!String.IsNullOrWhiteSpace(input.Lon))
            {
                callAttachment.Longitude = decimal.Parse(input.Lon);
            }

            _callsService.SaveCallAttachment(callAttachment);

            return(result);
        }
Exemplo n.º 4
0
        public CallAttachment SaveCallAttachment(CallAttachment attachment)
        {
            _callAttachmentRepository.SaveOrUpdate(attachment);

            return(attachment);
        }
Exemplo n.º 5
0
        public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority)
        {
            if (email == null)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(email.Body))
            {
                return(null);
            }

            if (String.IsNullOrEmpty(email.Subject))
            {
                return(null);
            }

            Call c = new Call();

            c.Notes = email.Subject + " " + email.Body;
            c.Name  = email.Subject;

            string[] data = email.Body.Split(char.Parse(","));

            if (data.Length >= 1)
            {
                int tryPriority;

                if (int.TryParse(data[0], out tryPriority))
                {
                    c.Priority = tryPriority;
                }
            }
            else
            {
                c.Priority = (int)CallPriority.High;
            }

            if (data.Length >= 2)
            {
                if (data[1].Length > 3)
                {
                    c.NatureOfCall = data[1];
                }
            }
            else
            {
                c.NatureOfCall = email.Body;
            }

            if (data.Length >= 3)
            {
                if (data[2].Length > 3)
                {
                    string address = String.Empty;

                    if (!data[2].Contains("United Kingdom"))
                    {
                        address = data[2] + "United Kingdom";
                    }

                    c.Address = address;
                }
            }

            c.LoggedOn         = DateTime.UtcNow;
            c.Priority         = priority;
            c.ReportingUserId  = managingUser;
            c.Dispatches       = new Collection <CallDispatch>();
            c.CallSource       = (int)CallSources.EmailImport;
            c.SourceIdentifier = email.MessageId;

            if (email.DispatchAudio != null)
            {
                c.Attachments = new Collection <CallAttachment>();

                CallAttachment ca = new CallAttachment();
                ca.FileName           = email.DispatchAudioFileName;
                ca.Data               = email.DispatchAudio;
                ca.CallAttachmentType = (int)CallAttachmentTypes.DispatchAudio;

                c.Attachments.Add(ca);
            }

            foreach (var u in users)
            {
                CallDispatch cd = new CallDispatch();
                cd.UserId = u.UserId;

                c.Dispatches.Add(cd);
            }

            return(c);
        }
Exemplo n.º 6
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.º 7
0
 public async Task <CallAttachment> SaveCallAttachmentAsync(CallAttachment attachment, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await _callAttachmentRepository.SaveOrUpdateAsync(attachment, cancellationToken));
 }
Exemplo n.º 8
0
        public async Task <IActionResult> Upload(UploadFileView model, IFormFile fileToUpload, CancellationToken cancellationToken)
        {
            string FileType = null;
            string FileName = null;

            byte[] Data = null;

            if (fileToUpload == null || fileToUpload.Length <= 0)
            {
                ModelState.AddModelError("fileToUpload", "You must select a file to upload.");
            }
            else
            {
                var extenion = fileToUpload.FileName.Substring(fileToUpload.FileName.IndexOf(char.Parse(".")) + 1,
                                                               fileToUpload.FileName.Length - fileToUpload.FileName.IndexOf(char.Parse(".")) - 1);

                if (!String.IsNullOrWhiteSpace(extenion))
                {
                    extenion = extenion.ToLower();
                }

                if (extenion != "jpg" && extenion != "jpeg" && extenion != "png" && extenion != "gif" && extenion != "gif" && extenion != "pdf" && extenion != "doc" &&
                    extenion != "docx" && extenion != "ppt" && extenion != "pptx" && extenion != "pps" && extenion != "ppsx" && extenion != "odt" &&
                    extenion != "xls" && extenion != "xlsx" && extenion != "mp3" && extenion != "m4a" && extenion != "ogg" && extenion != "wav" &&
                    extenion != "mp4" && extenion != "m4v" && extenion != "mov" && extenion != "wmv" && extenion != "avi" && extenion != "mpg" && extenion != "txt")
                {
                    ModelState.AddModelError("fileToUpload", string.Format("Document type ({0}) is not importable.", extenion));
                }

                if (fileToUpload.Length > 10000000)
                {
                    ModelState.AddModelError("fileToUpload", "Document is too large, must be smaller then 10MB.");
                }

                FileType = fileToUpload.ContentType;
                FileName = fileToUpload.FileName;

                var uploadedFile = new byte[fileToUpload.OpenReadStream().Length];
                fileToUpload.OpenReadStream().Read(uploadedFile, 0, uploadedFile.Length);

                Data = uploadedFile;
            }

            if (ModelState.IsValid)
            {
                switch ((FileUploadTypes)model.Type)
                {
                case FileUploadTypes.CallFile:
                    CallAttachment callAttachment = new CallAttachment();
                    callAttachment.CallId             = int.Parse(model.ResourceId);
                    callAttachment.CallAttachmentType = (int)CallAttachmentTypes.File;
                    callAttachment.Name     = model.Name;
                    callAttachment.FileName = FileName;
                    //callAttachment.FileType = FileType;
                    callAttachment.Size      = Data.Length;
                    callAttachment.Data      = Data;
                    callAttachment.Timestamp = DateTime.UtcNow;

                    if (!await _authorizationService.CanUserEditCallAsync(UserId, callAttachment.CallId))
                    {
                        Unauthorized();
                    }

                    await _callsService.SaveCallAttachmentAsync(callAttachment, cancellationToken);

                    return(RedirectToAction("ViewCall", "Dispatch", new { Area = "User", callId = callAttachment.CallId }));
                }
            }

            return(View(model));
        }
Exemplo n.º 9
0
        public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority)
        {
            if (email == null)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(email.Body))
            {
                return(null);
            }

            if (String.IsNullOrEmpty(email.Subject))
            {
                return(null);
            }

            if (!email.Subject.Contains("Perform Page"))
            {
                return(null);
            }

            Call c = new Call();

            c.Notes        = email.Subject + " " + email.Body;
            c.NatureOfCall = email.Body;

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

            string[] rawData = email.Body.Split(new string[] { "\r\n", "\r\n\r\n" }, StringSplitOptions.None);

            foreach (string s in rawData)
            {
                if (!string.IsNullOrWhiteSpace(s))
                {
                    data.Add(s);
                }
            }

            if (data.Count >= 1)
            {
                c.Name = data[0];
            }
            else
            {
                c.Name = email.Subject;
            }

            if (data.Count == 5)
            {
                string firstLine = string.Empty;

                if (data[1].ToUpper().Contains("AND"))
                {
                    string[] firstLineParts = data[1].Split(new string[] { "AND" }, StringSplitOptions.None);

                    if (!string.IsNullOrWhiteSpace(firstLineParts[0]))
                    {
                        firstLine = firstLineParts[0];
                    }
                }
                else if (data[1].ToUpper().Contains("/"))
                {
                    string[] firstLineParts = data[1].Split(new string[] { "/" }, StringSplitOptions.None);

                    if (!string.IsNullOrWhiteSpace(firstLineParts[0]))
                    {
                        firstLine = firstLineParts[0];
                    }
                }
                else
                {
                    firstLine = data[1];
                }

                c.Address = string.Format("{0} {1}", firstLine, data[2]);
            }
            else if (data.Count == 6)
            {
                c.Address = string.Format("{0} {1}", data[2], data[3]);
            }

            c.LoggedOn         = DateTime.UtcNow;
            c.Priority         = priority;
            c.ReportingUserId  = managingUser;
            c.Dispatches       = new Collection <CallDispatch>();
            c.CallSource       = (int)CallSources.EmailImport;
            c.SourceIdentifier = email.MessageId;

            if (email.DispatchAudio != null)
            {
                c.Attachments = new Collection <CallAttachment>();

                CallAttachment ca = new CallAttachment();
                ca.FileName           = email.DispatchAudioFileName;
                ca.Data               = email.DispatchAudio;
                ca.CallAttachmentType = (int)CallAttachmentTypes.DispatchAudio;

                c.Attachments.Add(ca);
            }

            foreach (var u in users)
            {
                CallDispatch cd = new CallDispatch();
                cd.UserId = u.UserId;

                c.Dispatches.Add(cd);
            }

            return(c);
        }