Ejemplo n.º 1
0
        public int GetDepartmentIdForType(NotificationItem ni)
        {
            switch ((EventTypes)ni.Type)
            {
            case EventTypes.PersonnelStaffingChanged:
                var state = _userStateService.GetUserStateById(ni.StateId);

                if (state != null)
                {
                    var department = _departmentsService.GetDepartmentByUserId(state.UserId, true);

                    if (department != null)
                    {
                        return(department.DepartmentId);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }

            case EventTypes.PersonnelStatusChanged:
                var status = _actionLogsService.GetActionlogById(ni.StateId);

                if (status != null)
                {
                    var department = _departmentsService.GetDepartmentByUserId(status.UserId, true);

                    if (department != null)
                    {
                        return(department.DepartmentId);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }

            case EventTypes.CalendarEventAdded:
                var cal = _calendarService.GetCalendarItemById(ni.ItemId);

                if (cal != null)
                {
                    return(cal.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.CalendarEventUpcoming:
                var calUp = _calendarService.GetCalendarItemById(ni.ItemId);

                if (calUp != null)
                {
                    return(calUp.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.CalendarEventUpdated:
                var calUpdate = _calendarService.GetCalendarItemById(ni.ItemId);

                if (calUpdate != null)
                {
                    return(calUpdate.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.DocumentAdded:
                var docAdded = _documentsService.GetDocumentById(ni.ItemId);

                if (docAdded != null)
                {
                    return(docAdded.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.LogAdded:
                var logAdded = _workLogsService.GetWorkLogById(ni.ItemId);

                if (logAdded != null)
                {
                    return(logAdded.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.NoteAdded:
                var noteAdded = _notesService.GetNoteById(ni.ItemId);

                if (noteAdded != null)
                {
                    return(noteAdded.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.ShiftCreated:
                var shiftCreated = _shiftsService.GetShiftById(ni.ItemId);

                if (shiftCreated != null)
                {
                    return(shiftCreated.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.ShiftDaysAdded:
                var shiftDaysAdded = _shiftsService.GetShiftById(ni.ItemId);

                if (shiftDaysAdded != null)
                {
                    return(shiftDaysAdded.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.ShiftUpdated:
                var shiftUpdated = _shiftsService.GetShiftById(ni.ItemId);

                if (shiftUpdated != null)
                {
                    return(shiftUpdated.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.UnitAdded:
                var unitAdded = _unitsService.GetUnitById(ni.UnitId);

                if (unitAdded != null)
                {
                    return(unitAdded.DepartmentId);
                }
                else
                {
                    return(0);
                }

            case EventTypes.UnitStatusChanged:
                var unitStatusChanged = _unitsService.GetUnitStateById(ni.StateId);

                if (unitStatusChanged != null)
                {
                    var unit = _unitsService.GetUnitById(unitStatusChanged.UnitId);

                    if (unit != null)
                    {
                        return(unit.DepartmentId);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(0);
                }
            }

            return(0);
        }