Exemplo n.º 1
0
        public static List <Notification> SelectAll(SQLiteConnection conn)
        {
            List <Notification> result = new List <Notification>();

            using (SQLiteCommand cmd = new SQLiteCommand(selectAll, conn))
            {
                SQLiteDataReader reader = null;
                try
                {
                    reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Notification nm = new Notification()
                        {
                            Id          = Convert.ToInt32(reader["Id"].ToString()),
                            Inspection  = InspectionDbMapper.SelectById(conn, Convert.ToInt32(reader["InspectionId"])),
                            Destination = reader["Destination"].ToString(),
                            SentOn      = Convert.ToDateTime(reader["SentOn"]),
                            Delivered   = Convert.ToDateTime(reader["Delivered"])
                        };
                        result.Add(nm);
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine($"EXCEPTION: NotificationDbMapper.SelectAll: {e.Message}");
                }
                finally
                {
                    reader?.Close();
                }
            }

            return(result);
        }
Exemplo n.º 2
0
 public static Notification SelectById(SQLiteConnection conn, int id)
 {
     using (SQLiteCommand cmd = new SQLiteCommand(selectById, conn))
     {
         cmd.Parameters.AddWithValue("@Id", id);
         SQLiteDataReader reader = null;
         try
         {
             reader = cmd.ExecuteReader();
             while (reader.Read())
             {
                 Notification nm = new Notification()
                 {
                     Id          = Convert.ToInt32(reader["Id"].ToString()),
                     Inspection  = InspectionDbMapper.SelectById(conn, Convert.ToInt32(reader["InspectionId"])),
                     Destination = reader["Destination"].ToString(),
                     SentOn      = Convert.ToDateTime(reader["SentOn"]),
                     Delivered   = Convert.ToDateTime(reader["Delivered"])
                 };
                 reader.Close();
                 return(nm);
             }
         }
         catch (Exception e)
         {
             reader?.Close();
             Trace.WriteLine($"EXCEPTION: NotificationDbMapper.SelectById: {e.Message}");
         }
     }
     return(null);
 }
Exemplo n.º 3
0
        public static List <Notification> GenerateNotifications(SQLiteConnection conn, int days)
        {
            List <Notification> result = new List <Notification>();

            using (SQLiteCommand cmd = new SQLiteCommand(generateNotifications, conn))
            {
                cmd.Parameters.AddWithValue("@days", days);
                SQLiteDataReader reader = null;
                try
                {
                    reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Notification nm = new Notification()
                        {
                            Id          = -1,
                            Inspection  = InspectionDbMapper.SelectById(conn, Convert.ToInt32(reader["InspectionId"])),
                            Destination = "",
                            SentOn      = DateTime.Now,
                            Delivered   = DateTime.Now
                        };

                        var vehicle = VehicleDbMapper.SelectById(conn, Convert.ToInt32(reader["VehicleId"]));
                        var boss    = UserBossDbMapper.SelectById(conn, vehicle.Boss.Id);
                        var email   = boss.Email;
                        nm.Destination = email;

                        result.Add(nm);
                    }
                }
                catch (Exception e)
                {
                    Trace.WriteLine($"EXCEPTION: NotificationDbMapper.SelectAll: {e.Message}");
                }
                finally
                {
                    reader?.Close();
                }
            }

            return(result);
        }