Ejemplo n.º 1
0
        private int AddCreditCard(CreditCardDetail crdObj)
        {
            if (crdObj == null)
            {
                return(0);
            }

            string queryString = @"IF (NOT EXISTS(SELECT id FROM master.[dbproject].[CreditCard] WHERE [cardNumber] = @cardNumber)) 
	                                    BEGIN 
	                                       INSERT INTO master.[dbproject].[CreditCard]([cardHolderName], [cardNumber], [expiryDate], [code], [bankName])
	                                        VALUES(@cardHolderName, @cardNumber, @expiryDate, @code, @bankName) 
                                    END 
                                    ELSE 
	                                    BEGIN 
	                                       UPDATE master.[dbproject].[CreditCard] 
			                                    SET [cardHolderName] = @cardHolderName,
				                                    [expiryDate] = @expiryDate,
				                                    [code] = @code,
				                                    [bankName] = @bankName
	                                       WHERE [cardNumber] = @cardNumber
                                    END ";

            SqlParameter[] param = new SqlParameter[5];
            param[0] = new SqlParameter("@cardHolderName", crdObj.cardHolderName);
            param[1] = new SqlParameter("@cardNumber", crdObj.cardNumber);
            param[2] = new SqlParameter("@expiryDate", crdObj.expiryDate);
            param[3] = new SqlParameter("@code", crdObj.code);
            param[4] = new SqlParameter("@bankName", crdObj.bankName);

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand command = new SqlCommand(queryString, connection))
                {
                    command.Connection.Open();
                    if (param != null)
                    {
                        command.Parameters.AddRange(param);
                    }

                    return(command.ExecuteNonQuery());
                }
            }
        }
Ejemplo n.º 2
0
 public BookViewModel(RoomDetail roomDetail)
 {
     this.roomDetail  = roomDetail;
     creditCardDetail = new CreditCardDetail();
     guestDetail      = new GuestDetail();
 }