Exemplo n.º 1
0
        public bool ValidateFilter(AlarmFilter alarmFilter)
        {
            if (alarmFilter.Id != 0)
            {
                this._Notifications.Add(new Notification
                {
                    field   = "Id",
                    value   = alarmFilter.Id,
                    message = "Id can't be different than 0."
                });
            }
            if (alarmFilter.StartDate == DateTime.MinValue)
            {
                this._Notifications.Add(new Notification
                {
                    field   = "StartDate",
                    value   = alarmFilter.StartDate,
                    message = "StartDate need to be defined with a valid value."
                });
            }
            if (alarmFilter.StartDate > alarmFilter.EndDate)
            {
                this._Notifications.Add(new Notification
                {
                    field   = "StartDate",
                    value   = alarmFilter.StartDate,
                    message = "StartDate can't be higher than EndDate."
                });
            }

            return(_Notifications.Count > 0 ? false : true);
        }
Exemplo n.º 2
0
        public List <Alarm> Filter(AlarmFilter alarm)
        {
            List <Alarm> alarms = new List <Alarm>();

            ApiConn.DAO.AddParameter("@Description", alarm.Description);
            ApiConn.DAO.AddParameter("@Id_Classification", alarm.Id_Classification);
            ApiConn.DAO.AddParameter("@Id_Equipment", alarm.Id_Equipment);
            ApiConn.DAO.AddParameter("@StartDate", alarm.StartDate);
            ApiConn.DAO.AddParameter("@EndDate", alarm.EndDate);

            string cmd = @"SELECT Id,Description,Id_Classification,Id_Equipment,RegisterDate
                           FROM Alarms WHERE
                           (
                                (@Description IS NULL) OR (Description LIKE @Description) AND
                                (@Id_Classification IS NULL) OR (Id_Classification = @Id_Classification) AND
                                (@Id_Equipment IS NULL) OR (Id_Equipment = @Id_Equipment) AND
                                (@StartDate IS NULL OR @EndDate IS NULL) OR (RegisterDate Between @StartDate AND @EndDate)
                           )";

            DataTable DT = ApiConn.DAO.ExecuteReader(cmd);

            foreach (DataRow row in DT.Rows)
            {
                alarms.Add(new Alarm
                {
                    Id = int.Parse(row["Id"].ToString()),
                    Id_Classification = int.Parse(row["Id_Classification"].ToString()),
                    Id_Equipment      = int.Parse(row["Id_Equipment"].ToString()),
                    Description       = row["Description"].ToString(),
                    RegisterDate      = (DateTime)row["RegisterDate"]
                });
            }
            return(alarms);
        }
Exemplo n.º 3
0
        public List <Alarm> Filter(AlarmFilter alarmFilter)
        {
            IntegityLayer.ValidateFilter(alarmFilter);

            if (IntegityLayer.Notifications.Count > 0)
            {
                this.Notifiable.Notifications = IntegityLayer.Notifications;
                this.Notifiable.StatusCode    = (int)HttpStatusCode.BadRequest;
                return(null);
            }

            List <Alarm> alarms = this.DAL.Filter(alarmFilter);

            this.Notifiable.StatusCode = (int)HttpStatusCode.OK;

            return(alarms);
        }