public Ticket AddTicket(int accountId, string device, string problem)
 {
   Ticket t = new HardwareTicket()
   {
     AccountId = accountId,
     Text = problem,
     DateOpened = DateTime.Now,
     State = TicketState.Open,
     DeviceName = device
   };
   return this.AddTicket(t);
 }
 public Domain.Ticket AddTicket(int acountID, string device, string problem)
 {
     Ticket t = new HardwareTicket()
     {
         AccountId = acountID,
         Text = problem,
         DateOpened = DateTime.Now,
         State = TicketState.Open,
         DeviceName = device
     };
     this.Validate(t);
     return repo.CreateTicket(t);
 }
    static void Main(string[] args)
    {
      // (1) Ticket validation
      Ticket t1 = new Ticket()
      {
        TicketNumber = 1,
        AccountId = 1,
        Text = "",
        State = TicketState.Open,
        DateOpened = DateTime.Now
      };

      // (2) HardwareTicket validation
      Ticket t2 = new HardwareTicket()
      {
        TicketNumber = 2,
        AccountId = 1,
        DeviceName = "LPT-9876",
        Text = "text",
        State = TicketState.Open,
        DateOpened = DateTime.Now
      };

      // (3) TicketResponse with user-defined validation
      TicketResponse tr = new TicketResponse()
      {
        Id = 1,
        Text = "response",
        IsClientResponse = true,
        Date = new DateTime(2014, 1, 1),
        Ticket = new Ticket()
        {
          TicketNumber = 3,
          AccountId = 1,
          Text = "text",
          State = TicketState.Open,
          DateOpened = new DateTime(2015, 1, 1)
        }
      };

      // Validatie controle
      var errors = new List<ValidationResult>();
      Validator.TryValidateObject(tr, new ValidationContext(tr), errors, validateAllProperties: true);

      Console.ReadLine();
    }
        static void Main(string[] args)
        {
            Ticket t2 = new HardwareTicket()
            {
                TicketNumber = 2,
                AccountId = 1,
                DeviceName = "LPT-9876",
                Text = "text",
                State = TicketState.Open,
                DateOpened = DateTime.Now
            };

            var errors = new List<ValidationResult>();
            Validator.TryValidateObject(t2, new ValidationContext(t2), errors, validateAllProperties: true);

            Console.ReadLine();
        }
    public IEnumerable<Ticket> ReadTickets()
    {
      List<Ticket> tickets = new List<Ticket>();

      string selectStatement = "SELECT TicketNumber, AccountId, [Text], DateOpened, State, DeviceName FROM Ticket";

      using (var connection = this.GetConnection())
      {
        SqlCommand command = new SqlCommand(selectStatement, connection);

        connection.Open();

        using (SqlDataReader reader = command.ExecuteReader())
        {
          int ticketNumberOrdinal = reader.GetOrdinal("TicketNumber");
          int accountIdOrdinal = reader.GetOrdinal("AccountId");
          int textOrdinal = reader.GetOrdinal("Text");
          int dateOpenedOrdinal = reader.GetOrdinal("DateOpened");
          int stateOrdinal = reader.GetOrdinal("State");
          int deviceNameOrdinal = reader.GetOrdinal("DeviceName");

          while (reader.Read())
          {
            Ticket ticket;
            string deviceName = reader.IsDBNull(deviceNameOrdinal) ? null : reader.GetString(deviceNameOrdinal);
            if (deviceName == null)
              ticket = new Ticket();
            else
              ticket = new HardwareTicket() { DeviceName = deviceName };

            ticket.TicketNumber = reader.GetInt32(ticketNumberOrdinal);
            ticket.AccountId = reader.GetInt32(accountIdOrdinal);
            ticket.Text = reader.GetString(textOrdinal);
            ticket.DateOpened = reader.GetDateTime(dateOpenedOrdinal);
            ticket.State = (TicketState)reader.GetByte(stateOrdinal);

            tickets.Add(ticket);
          }
          reader.Close(); // good practice!
        }
        connection.Close(); // good practice!
      }
      return tickets;
    }
        private void Seed()
        {
            tickets = new List<Ticket>();
            responses = new List<TicketResponse>();

            // Aanmaken eerste ticket met drie responses
            Ticket t1 = new Ticket()
            {
                TicketNumber = tickets.Count + 1,
                AccountId = 1,
                Text = "Ik kan mij niet aanmelden op de webmail",
                DateOpened = new DateTime(2012, 9, 9, 13, 5, 59),
                State = TicketState.Closed,
                Responses = new List<TicketResponse>()
            };

            tickets.Add(t1);

            TicketResponse t1r1 = new TicketResponse()
            {
                Id = responses.Count + 1,
                Ticket = t1,
                Text = "Account is geblokkeerd",
                Date = new DateTime(2012, 9, 9, 13, 24, 48),
                IsClientResponse = false
            };
            t1.Responses.Add(t1r1);
            responses.Add(t1r1);

            TicketResponse t1r2 = new TicketResponse()
            {
                Id = responses.Count + 1,
                Ticket = t1,
                Text = "Account terug in orde en nieuw paswoord ingesteld",
                Date = new DateTime(2012, 9, 9, 13, 29, 11),
                IsClientResponse = false
            };
            t1.Responses.Add(t1r2);
            responses.Add(t1r2);

            TicketResponse t1r3 = new TicketResponse()
            {
                Id = responses.Count + 1,
                Ticket = t1,
                Text = "Aanmelden gelukt en paswoord gewijzigd",
                Date = new DateTime(2012, 9, 10, 7, 22, 36),
                IsClientResponse = true
            };
            t1.Responses.Add(t1r3);
            responses.Add(t1r3);

            t1.State = TicketState.Closed;


            //Aanmaken tweede ticket met één response
            Ticket t2 = new Ticket()
            {
                TicketNumber = tickets.Count + 1,
                AccountId = 1,
                Text = "Geen internetverbinding",
                DateOpened = new DateTime(2012, 11, 5, 9, 45, 13),
                State = TicketState.Open,
                Responses = new List<TicketResponse>()
            };

            tickets.Add(t2);

            TicketResponse t2r1 = new TicketResponse()
            {
                Id = responses.Count + 1,
                Ticket = t2,
                Text = "Controleer of de kabel goed is aangesloten",
                Date = new DateTime(2012, 11, 5, 11, 25, 42),
                IsClientResponse = false
            };
            t2.Responses.Add(t2r1);
            responses.Add(t2r1);

            t2.State = TicketState.Answered;

            //Aanmaken eerste HardwareTicket
            HardwareTicket ht1 = new HardwareTicket()
            {
                TicketNumber = tickets.Count + 1,
                AccountId = 2,
                Text = "Blue screen!",
                DateOpened = new DateTime(2012, 12, 14, 19, 15, 32),
                State = TicketState.Open,
                //Responses = new List<TicketResponse>(),
                DeviceName = "PC-123456"
            };

            tickets.Add(ht1);
            this.CreateTickets(tickets);

        }
        public BL.Domain.Ticket ReadTicket(int ticketNumber)
        {
            Ticket ticket = null;

            string selectStatement = "SELECT TicketNumber, AccountId,[Text], DateOpened, State, DeviceNameFROM Ticket WHERE TicketNumber =@ticketNumber";

            using (var connection = this.GetConnection())
            {
                OleDbCommand command = new OleDbCommand(selectStatement, connection);
                command.Parameters.AddWithValue("@ticketNumber", ticketNumber);
                connection.Open();

                using (OleDbDataReader reader = command.ExecuteReader())
                {
                    int ticketNumberOrdinal = reader.GetOrdinal("TicketNumber");
                    int accountIdOrdinal = reader.GetOrdinal("AccountId");
                    int textOrdinal = reader.GetOrdinal("Text");
                    int dateOpenedOrdinal = reader.GetOrdinal("DateOpened");
                    int stateOrdinal = reader.GetOrdinal("State");
                    int deviceNameOrdinal = reader.GetOrdinal("DeviceName");

                    if (reader.Read())
                    {

                        string deviceName = reader.IsDBNull(deviceNameOrdinal) ? null : reader.GetString(deviceNameOrdinal);
                        if (deviceName == null)
                        {
                            ticket = new Ticket();
                        }
                        else
                            ticket = new HardwareTicket() { DeviceName = deviceName };

                        ticket.TicketNumber = reader.GetInt32(ticketNumberOrdinal);
                        ticket.AccountId = reader.GetInt32(accountIdOrdinal);
                        ticket.Text = reader.GetString(textOrdinal);
                        ticket.DateOpened = reader.GetDateTime(dateOpenedOrdinal);
                        ticket.State = (TicketState)reader.GetByte(stateOrdinal);
                    } reader.Close();
                } connection.Close();
            }
            return ticket;
        }
        public void Seed()
        {
            //Initialize the basic data of the application and/or some dummy data
            tickets = new List<Ticket>();
            responses = new List<TicketResponse>();

            // Create first ticket with three responses
            Ticket t1 = new Ticket()
            {
                TicketNumber = tickets.Count + 1,
                AccountId = 1,
                Text = "Ik kan mij niet aanmelden op de webmail",
                DateOpened = new DateTime(2012, 9, 9, 13, 5, 59),
                State = TicketState.Open,
                Responses = new List<TicketResponse>()
            };
            tickets.Add(t1);

            TicketResponse t1r1 = new TicketResponse()
            {
                Id = responses.Count + 1,
                Ticket = t1,
                Text = "Account was geblokkeerd",
                Date = new DateTime(2012, 9, 9, 13, 24, 48),
                IsClientResponse = false
            };
            t1.Responses.Add(t1r1);
            responses.Add(t1r1);

            TicketResponse t1r2 = new TicketResponse()
            {
                Id = responses.Count + 1,
                Ticket = t1,
                Text = "Account terug in orde en nieuw paswoord ingesteld",
                Date = new DateTime(2012, 9, 9, 13, 29, 11),
                IsClientResponse = false
            };
            t1.Responses.Add(t1r2);
            responses.Add(t1r2);

            TicketResponse t1r3 = new TicketResponse()
            {
                Id = responses.Count + 1,
                Ticket = t1,
                Text = "Aanmelden gelukt en paswoord gewijzigd",
                Date = new DateTime(2012, 9, 10, 7, 22, 36),
                IsClientResponse = true
            };
            t1.Responses.Add(t1r3);
            responses.Add(t1r3);
            t1.State = TicketState.Closed;

            //Second ticket
            Ticket t2 = new Ticket()
            {
                TicketNumber = tickets.Count + 1,
                AccountId = 1,
                Text = "Geen internetverbinding",
                DateOpened = new DateTime(2012, 11, 5, 9, 45, 13),
                State = TicketState.Open,
                Responses = new List<TicketResponse>()
            };
            tickets.Add(t2);

            TicketResponse t2r1 = new TicketResponse()
            {
                Id = responses.Count + 1,
                Ticket = t2,
                Text = "Controleer of de kabel goed is aangesloten",
                Date = new DateTime(2012, 11, 5, 11, 25, 42),
                IsClientResponse = false
            };
            t2.Responses.Add(t2r1);
            responses.Add(t2r1);
            t2.State = TicketState.Answered;

            HardwareTicket ht1 = new HardwareTicket()
            {
                TicketNumber = tickets.Count + 1,
                AccountId = 2,
                Text = "Blue screen!",
                DateOpened = new DateTime(2012, 12, 14, 19, 5, 2),
                State = TicketState.Open,
                DeviceName = "PC-123456"
            };
            tickets.Add(ht1);

        }