Exemple #1
0
            public static PersonnelViewModel Create(string name, ActionLog actionLog, UserState userState, Department department, DepartmentGroup respondingToDepartment, DepartmentGroup group, List <PersonnelRole> roles, string callNumber)
            {
                DateTime updateDate = TimeConverterHelper.TimeConverter(DateTime.UtcNow, department);

                string status          = "";
                string statusCss       = "";
                string state           = "";
                string stateCss        = "";
                string stateStyle      = "";
                string statusStyle     = "";
                double?latitude        = null;
                double?longitude       = null;
                int    statusValue     = 0;
                double eta             = 0;
                int    destinationType = 0;

                if (userState != null)
                {
                    if (userState.State <= 25)
                    {
                        if (userState.State == 0)
                        {
                            state    = "Available";
                            stateCss = "label-default";
                        }
                        else if (userState.State == 1)
                        {
                            state    = "Delayed";
                            stateCss = "label-warning";
                        }
                        else if (userState.State == 2)
                        {
                            state    = "Unavailable";
                            stateCss = "label-danger";
                        }
                        else if (userState.State == 3)
                        {
                            state    = "Committed";
                            stateCss = "label-info";
                        }
                        else if (userState.State == 4)
                        {
                            state    = "On Shift";
                            stateCss = "label-info";
                        }
                    }
                    else
                    {
                        var customState = CustomStatesHelper.GetCustomState(department.DepartmentId, userState.State);

                        if (customState != null)
                        {
                            state      = customState.ButtonText;
                            stateCss   = "label-default";
                            stateStyle = string.Format("color:{0};background-color:{1};", customState.TextColor, customState.ButtonColor);
                        }
                        else
                        {
                            state    = "Unknown";
                            stateCss = "label-default";
                        }
                    }
                }
                else
                {
                    state    = "Available";
                    stateCss = "label-default";
                }


                if (actionLog == null)
                {
                    status    = "Standing By";
                    statusCss = "label-default";
                }
                else
                {
                    updateDate      = TimeConverterHelper.TimeConverter(actionLog.Timestamp, department);
                    eta             = actionLog.Eta;
                    destinationType = actionLog.DestinationType.GetValueOrDefault();

                    statusValue = actionLog.ActionTypeId;

                    if (actionLog.ActionTypeId <= 25)
                    {
                        if (actionLog.ActionTypeId == 1)
                        {
                            status    = "Not Responding";
                            statusCss = "label-danger";
                        }
                        else if (actionLog.ActionTypeId == 2)
                        {
                            status    = "Responding";
                            statusCss = "label-success";

                            if (!String.IsNullOrWhiteSpace(actionLog.GeoLocationData))
                            {
                                var cords = actionLog.GetCoordinates();

                                latitude  = cords.Latitude;
                                longitude = cords.Longitude;
                            }
                        }
                        else if (actionLog.ActionTypeId == 0)
                        {
                            status    = "Standing By";
                            statusCss = "label-default";
                        }
                        else if (actionLog.ActionTypeId == 3)
                        {
                            status    = "On Scene";
                            statusCss = "label-inverse";
                        }
                        else if (actionLog.ActionTypeId == 4)
                        {
                            if (respondingToDepartment == null)
                            {
                                status = "Available Station";
                            }
                            else
                            {
                                status = string.Format("Available at {0}", respondingToDepartment.Name);
                            }

                            statusCss = "label-default";
                        }
                        else if (actionLog.ActionTypeId == 5)
                        {
                            statusCss = "label-success";

                            if (!String.IsNullOrWhiteSpace(actionLog.GeoLocationData))
                            {
                                var cords = actionLog.GetCoordinates();

                                latitude  = cords.Latitude;
                                longitude = cords.Longitude;
                            }

                            if (respondingToDepartment == null)
                            {
                                status = "Responding to Station";
                            }
                            else
                            {
                                status = string.Format("Responding to {0}", respondingToDepartment.Name);
                            }
                        }
                        else if (actionLog.ActionTypeId == 6)
                        {
                            statusCss = "label-success";

                            if (!String.IsNullOrWhiteSpace(actionLog.GeoLocationData))
                            {
                                var cords = actionLog.GetCoordinates();

                                latitude  = cords.Latitude;
                                longitude = cords.Longitude;
                            }

                            if (!actionLog.DestinationId.HasValue)
                            {
                                status = "Responding to Call";
                            }
                            else
                            {
                                if (!String.IsNullOrWhiteSpace(callNumber))
                                {
                                    status = string.Format("Responding to Call {0}", callNumber);
                                }
                                else
                                {
                                    status = string.Format("Responding to Call {0}", actionLog.DestinationId);
                                }
                            }
                        }
                    }
                    else
                    {
                        var customStatus = CustomStatesHelper.GetCustomState(department.DepartmentId, actionLog.ActionTypeId);

                        if (customStatus != null)
                        {
                            status      = customStatus.ButtonText;
                            statusCss   = "label-default";
                            statusStyle = string.Format("color:{0};background-color:{1};", customStatus.TextColor, customStatus.ButtonColor);

                            if (!String.IsNullOrWhiteSpace(actionLog.GeoLocationData))
                            {
                                var cords = actionLog.GetCoordinates();

                                latitude  = cords.Latitude;
                                longitude = cords.Longitude;
                            }
                        }
                        else
                        {
                            status    = "Unknown";
                            statusCss = "label-default";
                        }
                    }
                }

                string groupName = "";
                int    groupId   = 0;

                if (group != null)
                {
                    groupName = group.Name;
                    groupId   = group.DepartmentGroupId;
                }

                var newRoles = new StringBuilder();

                foreach (var role in roles)
                {
                    if (newRoles.Length > 0)
                    {
                        newRoles.Append(", " + role.Name);
                    }
                    else
                    {
                        newRoles.Append(role.Name);
                    }
                }

                return(new PersonnelViewModel
                {
                    Name = name,
                    Status = status,
                    StatusCss = statusCss,
                    State = state,
                    StateCss = stateCss,
                    UpdatedDate = updateDate,
                    Group = groupName,
                    Roles = newRoles.ToString(),
                    GroupId = groupId,
                    StateStyle = stateStyle,
                    StatusStyle = statusStyle,
                    Latitude = latitude,
                    Longitude = longitude,
                    StatusValue = statusValue,
                    Eta = eta,
                    DestinationType = destinationType
                });
            }