public Ticket CreateTicket(Ticket ticket)
        {
            string insertStatement = "INSERT INTO Ticket(AccountId, [Text], DateOpened, " +
                                     "State, DeviceName) VALUES(@accountId, " +
                                     "@text, @dateOpened, @state, @dviceName)";
            using (SqlConnection conn = this.GetConnection())
            {
                SqlCommand command = new SqlCommand(insertStatement, conn);
                command.Parameters.AddWithValue("@accountId", ticket.AccountId);
                command.Parameters.AddWithValue("@DateOpened", ticket.DateOpened.ToString(("yyyy-MM-dd HH:mm:ss")));
                command.Parameters.AddWithValue("@state", (byte) ticket.State); // Typecasting to byte, but why

                if (ticket is HardwareTicket)
                {
                    command.Parameters.AddWithValue("@deviceName", ((HardwareTicket) ticket).DeviceName);
                }
                else
                {
                    command.Parameters.AddWithValue(("@deviceName"), DBNull.Value);
                }

                command.CommandText += "; SELECT SCOPE_IDENTITY();"; // Grabs the primary key of the newly inserted ticket
                conn.Open();

                ticket.TicketNumber = Convert.ToInt32(command.ExecuteScalar());
                conn.Close();
            }
            return ticket;
        }
        public Ticket CreateTicket(Ticket ticket)
        {
            ctx.Tickets.Add(ticket);
            ctx.SaveChanges();

            return ticket; // Has been created by the database!
        }
 public void UpdateTicket(Ticket ticket)
 {
   // Make sure that 'ticket' is known by context
   // and has state 'Modified' before updating to database
   ctx.Entry(ticket).State = System.Data.Entity.EntityState.Modified;
   ctx.SaveChanges();
 }
        public ActionResult Create(Ticket ticket, FormCollection collection)
        {
            if(ModelState.IsValid)
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
                return View();
        }
Exemplo n.º 5
0
 public HardwareTicket(Ticket t, string deviceName)
 {
     this.AccountId = t.AccountId;
     this.CreationDate = t.CreationDate;
     this.DeviceName = deviceName;
     this.Id = t.Id;
     this.Responses = t.Responses;
     this.State = t.State;
     this.Text = t.Text;
 }
 public ActionResult Edit(int id, Ticket ticket)
 {
     if(ModelState.IsValid)
     {
         // TODO: Add update logic here
         mgr.ChangeTicket(ticket);
         return RedirectToAction("Index");
     }
         return View();
 }
 public Ticket AddTicket(int accountId, string question)
 {
   Ticket t = new Ticket()
   {
     AccountId = accountId,
     Text = question,
     DateOpened = DateTime.Now,
     State = TicketState.Open,
   };
   return this.AddTicket(t);
 }
        public ActionResult Create(Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                ticket = mgr.AddTicket(ticket.AccountId, ticket.Text);

                return RedirectToAction("Details", new { id = ticket.TicketNumber });
            }

            return View();
        }
Exemplo n.º 9
0
 public Domain.Ticket AddTicket(int acountID, string question)
 {
     Domain.Ticket t = new Domain.Ticket()
     {
         AccountId = acountID,
         Text = question,
         DateOpened = DateTime.Now,
         State = Domain.TicketState.Open,
     };
     this.Validate(t);
     return repo.CreateTicket(t);
 }
 // GET: Ticket/Create
 public ActionResult Create(Ticket ticket)
 {
     try
     {
         ticket = mgr.AddTicket(ticket.AccountId, ticket.Text);
         return RedirectToAction("Details", new {id = ticket.TicketNumber});
     }
     catch (Exception)
     {
         return View();
     }
 }
Exemplo n.º 11
0
 public ActionResult Create(Ticket ticket)
 {
     try
     {
         // TODO: Add insert logic here
         ticket = mgr.AddTicket(ticket.AccountId, ticket.Text);
         return RedirectToAction("Details", new { id=ticket.TicketNumber});
     }
     catch
     {
         return View();
     }
 }
        public IEnumerable<Ticket> ReadTickets()
        {
            List<Ticket> tickets = new List<Ticket>();

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

            using (SqlConnection conn = GetConnection())
            {
                SqlCommand cmd = new SqlCommand(query, conn);
                conn.Open();

                using (SqlDataReader reader = cmd.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();
                    
                }
                conn.Close();
            }
            return tickets;
        }
Exemplo n.º 13
0
    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();
    }
 public void ChangeTicket(Ticket ticket)
 {
   this.Validate(ticket);
   repo.UpdateTicket(ticket);
 }
Exemplo n.º 15
0
 public Ticket CreateTicket(Ticket ticket)
 {
     using (var session = _sessionFactory.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Save(ticket);
             transaction.Commit();
         }
     }
     return ticket;
 }
Exemplo n.º 16
0
 private void Validate(Ticket ticket)
 {
     Validator.ValidateObject(ticket, new ValidationContext(ticket)
     , validateAllProperties: true);
 }
 private Ticket AddTicket(Ticket ticket)
 {
   this.Validate(ticket);
   return repo.CreateTicket(ticket);
 }
Exemplo n.º 18
0
        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;
        }
    private void Validate(Ticket ticket)
    {
      //Validator.ValidateObject(ticket, new ValidationContext(ticket), validateAllProperties: true);

      List<ValidationResult> errors = new List<ValidationResult>();
      bool valid = Validator.TryValidateObject(ticket, new ValidationContext(ticket), errors, validateAllProperties: true);

      if (!valid)
        throw new ValidationException("Ticket not valid!");
    }
Exemplo n.º 20
0
        private static void PrintTicketDetails(Ticket ticket)
        {
            Console.WriteLine("{0,-15}: {1}", "Ticket", ticket.TicketNumber);
            Console.WriteLine("{0,-15}: {1}", "Gebruiker", ticket.AccountId);
            Console.WriteLine("{0,-15}: {1}", "Datum", ticket.DateOpened.ToString("dd/MM/yyyy"));
            Console.WriteLine("{0,-15}: {1}", "Status", ticket.State);

            if(ticket is HardwareTicket)
            {
                Console.WriteLine("{0,-15}: {1}", "Toestel", ((HardwareTicket)ticket).DeviceName);
            }

            Console.WriteLine("{0,-15}: {1}", "Vraag/probleem", ticket.Text);
        }
Exemplo n.º 21
0
        public IEnumerable<BL.Domain.Ticket> ReadTickets()
        {
            List<Ticket> tickets = new List<Ticket> { };

            string selectStatement = "SELECT TicketNumber, AccountId, [Text], DateOpened, State, DeviceName FROM Ticket";
            using (var connection = this.GetConnection()){
                OleDbCommand command = new OleDbCommand(selectStatement, connection);
                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");

                    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();
                } connection.Close();
            }
            return tickets;
        }
 public Ticket CreateTicket(Ticket ticket)
 {
     ticket.TicketNumber = tickets.Count + 1;
     tickets.Add(ticket);
     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);

        }
 public void UpdateTicket(Ticket ticket)
 {
     // Do nothing! All data lives in memory, so everything references the same objects!!
 }
        private void Validate(Ticket ticket) 
        {
            List<ValidationResult> errors = new List<ValidationResult>();

            //'TryValidateObject' maakt het mogelijk om in debug (via variabele 'errors') alle ongeldige validaties te bekijken! (werkt het ook niet in release?)
            bool valid = Validator.TryValidateObject(ticket, new ValidationContext(ticket), errors, validateAllProperties: true);

            if (!valid) 
            {
                throw new ValidationException("Ticket not valid!");
            }
        }
Exemplo n.º 26
0
 public void ChangeTicket(Ticket ticket)
 {
     //
 }
Exemplo n.º 27
0
 public void UpdateTicket(Ticket ticket)
 {
     using (var session = _sessionFactory.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Update(ticket);
             transaction.Commit();
             session.Close();
         }
     }
 }
 public void UpdateTicket(Ticket ticket)
 {
     //Make sure that the ticket is known by the context, and has "modified" before being sent to the DB.
     ctx.Entry(ticket).State = System.Data.Entity.EntityState.Modified;
     ctx.SaveChanges();
 }
Exemplo n.º 29
0
        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);

        }
Exemplo n.º 30
0
 public void UpdateTicket(Ticket ticket)
 {
     //DoNothing
 }