public TicketResponse CreateTicketResponse(TicketResponse response)
        {
            ctx.TicketResponses.Add(response);
            ctx.SaveChanges();

            return response; // 'Id' has been created by DB.
        }
Esempio n. 2
0
 public TicketResponse AddTicketResponse(int ticketNumber, string response, bool isClientResponse)
 {
     Ticket ticketToAddResponseTo = this.GetTicket(ticketNumber);
       if (ticketToAddResponseTo != null)
       {
     // Create response
     TicketResponse newTicketResponse = new TicketResponse();
     newTicketResponse.Date = DateTime.Now;
     newTicketResponse.Text = response;
     newTicketResponse.IsClientResponse = isClientResponse;
     newTicketResponse.Ticket = ticketToAddResponseTo;
     // Add response to ticket
     var responses = this.GetTicketResponses(ticketNumber);
     if (responses != null)
       ticketToAddResponseTo.Responses = responses.ToList();
     else
       ticketToAddResponseTo.Responses = new List<TicketResponse>();
     ticketToAddResponseTo.Responses.Add(newTicketResponse);
       if (isClientResponse)
       ticketToAddResponseTo.State = TicketState.ClientAnswer;
     else
       ticketToAddResponseTo.State = TicketState.Answered;
     // Save changes to repository
     this.Validate(newTicketResponse);
     this.Validate(ticketToAddResponseTo);
     repo.CreateTicketResponse(newTicketResponse);
     repo.UpdateTicket(ticketToAddResponseTo);
     return newTicketResponse;
       }
       else
     throw new ArgumentException("Ticketnumber '" + ticketNumber + "' not found!");
 }
 public static void Main(string[] args)
 {
     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) }
       };
       var errors = new List<ValidationResult>(); Validator.TryValidateObject(tr, new ValidationContext(tr), errors, true); Console.ReadLine();
 }
    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();
    }
Esempio n. 5
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);

        }
Esempio n. 6
0
 public TicketResponse CreateTicketResponse(TicketResponse response)
 {
     using (var session = _sessionFactory.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Save(response);
             transaction.Commit();
         }
     }
     return response;
 }
    private void Validate(TicketResponse response)
    {
      //Validator.ValidateObject(response, new ValidationContext(response), validateAllProperties: true);

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

      if (!valid)
        throw new ValidationException("TicketResponse not valid!");
    }
        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 TicketResponse CreateTicketResponse(TicketResponse response)
        {
            response.Id = responses.Count + 1;
            responses.Add(response);

            return response;
        }
 private void Validate(TicketResponse response) 
 {
     Validator.ValidateObject(response, new ValidationContext(response), validateAllProperties: true);
 }
        public TicketResponse CreateTicketResponse(TicketResponse response)
        {
            if (response.Ticket != null)
            {
                string insertStatement = "INSERT INTO TicketResponse([Text], [Date], IsClientResponse, " +
                                         "Ticket_TicketNumber) VALUES (@text, @date, " +
                                         "@isClientResponse, @ticketNumber)";

                using (SqlConnection conn = this.GetConnection())
                {
                    SqlCommand command = new SqlCommand(insertStatement, conn);
                    command.Parameters.AddWithValue("@text", response.Text);
                    command.Parameters.AddWithValue("@date", response.Date.ToString("yyyy-MM-dd HH:mm:ss"));
                    command.Parameters.AddWithValue("@isClientResponse", response.IsClientResponse);
                    command.Parameters.AddWithValue("@tickedNumber", response.Ticket.TicketNumber);
                    //Retrieve primary key 'Id' of inserted response
                    command.CommandText += "; SELECT SCOPE_IDENTITY;";

                    conn.Open();
                    response.Id = Convert.ToInt32(command.ExecuteScalar());
                    conn.Close();
                }
                return response;
            }
            else
            {
                throw new ArgumentException("The ticketresponse has no  ticket attached to it");
            }
        }