public bool ValidateFilter(ActedAlarmFilter actedAlarmFilter) { if (actedAlarmFilter.Id != 0) { this._Notifications.Add(new Notification { field = "Id", value = actedAlarmFilter.Id, message = "Id can't be different than 0." }); } if (actedAlarmFilter.StartDate == DateTime.MinValue) { this._Notifications.Add(new Notification { field = "StartDate", value = actedAlarmFilter.StartDate, message = "StartDate need to be defined with a valid value." }); } if (actedAlarmFilter.StartDate > actedAlarmFilter.EndDate) { this._Notifications.Add(new Notification { field = "StartDate", value = actedAlarmFilter.StartDate, message = "StartDate can't be higher than EndDate." }); } return(_Notifications.Count > 0 ? false : true); }
public List <ActedAlarm> Filter(ActedAlarmFilter actedAlarmFilter) { IntegityLayer.ValidateFilter(actedAlarmFilter); if (IntegityLayer.Notifications.Count > 0) { this.Notifiable.Notifications = IntegityLayer.Notifications; this.Notifiable.StatusCode = (int)HttpStatusCode.BadRequest; return(null); } List <ActedAlarm> actedAlarms = this.DAL.Filter(actedAlarmFilter); this.Notifiable.StatusCode = (int)HttpStatusCode.OK; return(actedAlarms); }
public List <ActedAlarm> Filter(ActedAlarmFilter actedAlarmFilter) { List <ActedAlarm> actedAlarmFiltered = new List <ActedAlarm>(); ApiConn.DAO.AddParameter("@StartDate", actedAlarmFilter.StartDate); ApiConn.DAO.AddParameter("@AlarmDescription", actedAlarmFilter.AlarmDescription); ApiConn.DAO.AddParameter("@EndDate", actedAlarmFilter.EndDate); string cmd = @"SELECT AC.Id, AC.InputDate,AC.OutputDate, A.Description as AlarmDescription, E.Name as EquipmentName,E.Description as EquipmentDescription, S.Value as AlarmStatus, AC.RegisterDate as AcRegisterDate FROM Alarms_Acted AC INNER JOIN Alarms A ON A.Id = AC.Id_Alarm INNER JOIN Equipments E ON E.Id = A.Id_Equipment INNER JOIN Alarms_Status S ON S.Id = AC.Id_Status WHERE ( (@StartDate IS NULL OR @EndDate IS NULL) OR (AC.RegisterDate Between @StartDate AND @EndDate) AND (@AlarmDescription IS NULL OR @AlarmDescription = '') OR (A.Description LIKE @AlarmDescription) )"; DataTable DT = ApiConn.DAO.ExecuteReader(cmd); foreach (DataRow row in DT.Rows) { actedAlarmFiltered.Add(new ActedAlarm { Id = int.Parse(row["Id"].ToString()), AlarmStatus = row["AlarmStatus"].ToString(), AlarmDescription = row["AlarmDescription"].ToString(), EquipmentDescription = row["EquipmentDescription"].ToString(), InputDate = row["InputDate"] != DBNull.Value ? (DateTime)row["InputDate"] : DateTime.MinValue, OutputDate = row["OutputDate"] != DBNull.Value ? (DateTime)row["OutputDate"] : DateTime.MinValue, RegisterDate = row["AcRegisterDate"] != DBNull.Value ? (DateTime)row["AcRegisterDate"]:DateTime.MinValue, }); } return(actedAlarmFiltered); }